Jump to content

Recommended Posts

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);
Link to comment
https://forums.phpfreaks.com/topic/284837-bbcode-parsing-issue/
Share on other sites

  • 3 weeks later...
  • 4 weeks later...

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

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.