Jump to content


Changing To A Link (PHP)


2 replies to this topic

#1 Hip Hop Artist

    Young Padawan

  • Members
  • Pip
  • 152 posts
  • Gender:Male
  • Location:Canada

Posted 03 September 2007 - 12:12 PM

For my news section of my site I need a script that will take any urls that were typed into the body of text and turn them into links. Or that I can put a word right after the url and it will make whatever word i put into a link to the url i typed.

Edited by Hip Hop Artist, 03 September 2007 - 12:12 PM.


#2 Balor

    PHP Nerd

  • Members
  • Pip
  • 63 posts
  • Gender:Male
  • Location:Germany->Frankfurt
  • Interests:My beautyful girl, my son and webcoding. I'm also very interested in art but I'm not really good at art... it's sad but true ^^

Posted 03 September 2007 - 12:22 PM

What you want is something like a bbcode system, you can find some nice tutorials about exaclty this. Also check str_replace and preg_replace in php.net function list! Next thing would be regular expressions.

Edited by Balor, 03 September 2007 - 12:24 PM.


#3 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 03 September 2007 - 01:44 PM

A solution would be to search your text for 'http://' or even 'www' and to let php select the sentence until a space: ' ' is found. And put that in a <a> tag.

To search a text for words/characters, refer to:
http://be2.php.net/m...tion.strpos.php and http://be2.php.net/m...tion.strstr.php





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users