Jump to content

[SOLVED] regex help


Renlok

Recommended Posts

i have bbcode but i'm having problems with it, half the bbcode doesn't work and ive no idea why and rubbish at using regex and this is the onyl time ive ever used it so its probably just written rubbish but i dunno any hellp would be great

 

..ill just post the bits that don't work.

 

$string = $_POST['message'];

$patterns = array( 
'`\[color=#([0-9]{6})\](.+?)\[/color\]`is', 
'`\[colour=#([0-9]{6})\](.+?)\[/colour\]`is',
'`\[color=([a-z])\](.+?)\[/color\]`is',
'`\[colour=([a-z])\](.+?)\[/colour\]`is',
'`\[img\](.+?)\[/img\]`is', 
'`\[url=([a-z0-9]+://)([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\](.*?)\[/url\]`si', 
'`\[url\]([a-z0-9]+?://){1}([\w\-]+\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*)?)\[/url\]`si', 
'`\[url\]((www|ftp)\.([\w\-]+\.)*[\w]+(:[0-9]+)?(/[^ \"\n\r\t<]*?)?)\[/url\]`si', 
); 

$replaces =  array( 
'<span style="color:#\1;">\2</span>',
'<span style="color:#\1;">\2</span>', 
'<span style="color:\1;">\2</span>',
'<span style="color:\1;">\2</span>',
'<img src="\1" alt="" style="border:0px;" />', 
'<a href="\1\2">\6</a>', 
'<a href="\1\2">\1\2</a>', 
'<a href="http://\1">\1</a>', 
); 


$string = preg_replace($patterns, $replaces , $string); 

 

i have loads of other parts to the bbcode that work fine i dont know why these bits just dont work

Link to comment
https://forums.phpfreaks.com/topic/56602-solved-regex-help/
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.