GamerGun Posted January 26, 2010 Share Posted January 26, 2010 Hello all, I am creating a shoutbox, which goes fine. It saves all text to some .txt file, which i then read. With some ereg_replace i make all tekst links clickable (hyperlink). The only problem is that it also converts things like <img src="bla"> so all images become broken. Any idea? Short said: I dont want the ereg_replace to touch links ending with .gif or whatever! Thanks! <html> <head> <?php header('Refresh: 120'); ?> </head> <body> <b>Roept u maar</b><br><br> <?php $read = fopen("content.txt", "r"); $contents = fread($read, filesize('content.txt')); $bbcode = array( '#\[b\](.*?)\[/b\]#si' => '<b>\\1</b>', '#\[i\](.*?)\[/i\]#si' => '<i>\\1</i>', '#\[u\](.*?)\[/u\]#si' => '<u>\\1</u>', '#\[s\](.*?)\[/s\]#si' => '<strike>\\1</strike>', '#\[color=(.*?)\](.*?)\[/color\]#si' => '<font color="\\1">\\2</font>', '#\[img\](.*?)\[/img\]#si' => '<img src="\\1">', '#\[email\](.*?)\[/email\]#si' => '<a href="mailto:\\1">\\1</a>' ); $contents = preg_replace(array_keys($bbcode), array_values($bbcode), $contents); $contents = str_replace("www","http://www",$contents); $smilies = array("","","","",":shock:",":?","","",":x","",":red:","",":evil:",":twisted:",":roll:",":wink:",":!:",":q","",":arrow:"); $images = array("icon_biggrin.gif","icon_smile.gif","icon_sad.gif","icon_surprised.gif","icon_eek.gif","icon_confused.gif","icon_cool.gif","icon_lol.gif","icon_mad.gif","icon_razz.gif","icon_redface.gif","icon_cry.gif","icon_evil.gif","icon_twisted.gif","icon_rolleyes.gif","icon_wink.gif","icon_exclaim.gif","icon_question.gif","icon_idea.gif","icon_arrow.gif"); $aantal = count($smilies)-1; for ($i=0;$i<=$aantal;$i++) { $contents = str_replace($smilies[$i],"<img src=\"/shoutbox/smileys/".$images[$i]."\"WIDTH=\"15\" HEIGHT=\"15\">", $contents); } echo $contents; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/189866-ereg_replace-and-exclude/ Share on other sites More sharing options...
GamerGun Posted January 27, 2010 Author Share Posted January 27, 2010 Damn, i did paste the wrong code; <html> <head> <?php header('Refresh: 120'); ?> </head> <body> <b>Roept u maar</b><br><br> <?php $read = fopen("content.txt", "r"); $contents = fread($read, filesize('content.txt')); $bbcode = array( '#\[b\](.*?)\[/b\]#si' => '<b>\\1</b>', '#\[i\](.*?)\[/i\]#si' => '<i>\\1</i>', '#\[u\](.*?)\[/u\]#si' => '<u>\\1</u>', '#\[s\](.*?)\[/s\]#si' => '<strike>\\1</strike>', '#\[color=(.*?)\](.*?)\[/color\]#si' => '<font color="\\1">\\2</font>', '#\[img\](.*?)\[/img\]#si' => '<img src="\\1">', '#\[email\](.*?)\[/email\]#si' => '<a href="mailto:\\1">\\1</a>' ); $contents = preg_replace(array_keys($bbcode), array_values($bbcode), $contents); $contents = str_replace("www","http://www",$contents); $smilies = array("","","","",":shock:",":?","","",":x","",":red:","",":evil:",":twisted:",":roll:",":wink:",":!:",":q","",":arrow:"); $images = array("icon_biggrin.gif","icon_smile.gif","icon_sad.gif","icon_surprised.gif","icon_eek.gif","icon_confused.gif","icon_cool.gif","icon_lol.gif","icon_mad.gif","icon_razz.gif","icon_redface.gif","icon_cry.gif","icon_evil.gif","icon_twisted.gif","icon_rolleyes.gif","icon_wink.gif","icon_exclaim.gif","icon_question.gif","icon_idea.gif","icon_arrow.gif"); $aantal = count($smilies)-1; for ($i=0;$i<=$aantal;$i++) { $contents = str_replace($smilies[$i],"<img src=\"/shoutbox/smileys/".$images[$i]."\"WIDTH=\"15\" HEIGHT=\"15\">", $contents); } $contents = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]", "<a href=\"\\0\">\\0</a>", $contents); echo $contents; ?> </body> </html> See the ereg_replace line. This is the result: [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/189866-ereg_replace-and-exclude/#findComment-1002277 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.