supanoob Posted July 8, 2008 Share Posted July 8, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/113787-str_replace/ Share on other sites More sharing options...
mbeals Posted July 8, 2008 Share Posted July 8, 2008 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 ) Quote Link to comment https://forums.phpfreaks.com/topic/113787-str_replace/#findComment-584742 Share on other sites More sharing options...
supanoob Posted July 8, 2008 Author Share Posted July 8, 2008 yes if i do that ima still have the problem of [ becomeing < etc because im still going to have to convert them. Quote Link to comment https://forums.phpfreaks.com/topic/113787-str_replace/#findComment-584750 Share on other sites More sharing options...
mbeals Posted July 8, 2008 Share Posted July 8, 2008 so you use preg_match to get the parts, build a real hyperlink from them, then use a normal str_replace to replace the entire string with the new one. Quote Link to comment https://forums.phpfreaks.com/topic/113787-str_replace/#findComment-584753 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.