Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.