liamdawe Posted December 18, 2013 Share Posted December 18, 2013 Hi all currently I am parsing some simple bbcode like urls, images, bold etc. I have just added it so all images are turned into links to themselves so if the image is too big they can click on it for the full picture. The problem is if someone wants a picture to link to something other than itself that now doesn't work. I am trying to counter it by parsing images that have a manual url attached to them first like so: $find = array( "/\[url\=(.+?)\]\[img\](.+?)\[\/img\]\[\/url\]/is", ); $replace = array( "<a href=\"$1\" target=\"_blank\"><img src=\"$2\" class=\"bbcodeimage img-polaroid\" alt=\"image\" /></a>", ); $body = preg_replace($find, $replace, $body); The problem is it seems to mess up the rest of the url parsing, is there something I am doing wrong? This code is directly after to parse normal links, the above code seems to also mess this up: $find = array( "/\[url\=(.+?)\](.+?)\[\/url\]/is", "/\[url\](.+?)\[\/url\]/is" ); $replace = array( "<a href=\"$1\" target=\"_blank\">$2</a>", "<a href=\"$1\" target=\"_blank\">$1</a>" ); $body = preg_replace($find, $replace, $body); Quote Link to comment https://forums.phpfreaks.com/topic/284837-bbcode-parsing-issue/ Share on other sites More sharing options...
requinix Posted December 18, 2013 Share Posted December 18, 2013 Replace a nested http://...... before you do the s and s. Quote Link to comment https://forums.phpfreaks.com/topic/284837-bbcode-parsing-issue/#findComment-1462677 Share on other sites More sharing options...
liamdawe Posted December 20, 2013 Author Share Posted December 20, 2013 That's what I am trying to do in the code above, but it seems to not work correctly to the point of not parsing certain urls at all. Quote Link to comment https://forums.phpfreaks.com/topic/284837-bbcode-parsing-issue/#findComment-1462826 Share on other sites More sharing options...
liamdawe Posted January 6, 2014 Author Share Posted January 6, 2014 Sorry to bump, but I am still stuck on this. What would be the best way to replace nested tags like that before the normal img tag converter? Quote Link to comment https://forums.phpfreaks.com/topic/284837-bbcode-parsing-issue/#findComment-1464117 Share on other sites More sharing options...
ocpaul20 Posted January 29, 2014 Share Posted January 29, 2014 for others coming after, Dont know whether the end requirement is to convert to HTML or not but why not use something like the BBCode parser in PEAR. I have just found it so I know very little about it, but it is in PEAR and so many people must use it for this kind of thing. Then you can parse the HTML with standard routines. HTML BBCode Parser2 PEAR package Quote Link to comment https://forums.phpfreaks.com/topic/284837-bbcode-parsing-issue/#findComment-1466901 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.