Jump to content

str_replace


supanoob

Recommended Posts

basically i have a forum system. the system used codes such as:

 

[b][/b] for bold
[u][/u] for underline
[url=*url*]Link name[/url] to link

 

Now the problem i have is when i replace all those [ and ] for < and > if someone types a normal [ or ] without it being linked to that code it turns it into a < or >.

 

Now i know how to fix it for most things, but when it comes to the one i cant think of a way to get the closed bracket onto it. Any idea?

Link to comment
https://forums.phpfreaks.com/topic/113787-str_replace/
Share on other sites

i would use preg_match to match the entire thing and pick it apart.

 

Something like

 


$url = '[url=http://www.phpfreaks.com/forums/index.php?action=post;topic=205723.0;num_replies=0]Link Title[url]';

preg_match("/\[url=(.*?)](.*?)\[url\]/",$url,$matches);


print_r($matches);

 

 

gives

 

Array
(
    [0] => [url=http://www.phpfreaks.com/forums/index.php?action=post;topic=205723.0;num_replies=0]Link Title[url]
    [1] => http://www.phpfreaks.com/forums/index.php?action=post;topic=205723.0;num_replies=0
    [2] => Link Title
)

 

Link to comment
https://forums.phpfreaks.com/topic/113787-str_replace/#findComment-584742
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.