Jump to content

Wrapping paragraph tags around text


jordanwb

Recommended Posts

I'm making a website and I'm making it so that the guy can add his own pages. Here's basically what I'd want him to be able to do as well as the result:

 

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Mauris tempor. Donec mollis suscipit arcu. Vestibulum.

[b]Lorem ipsum dolor sit amet, consectetuer adipiscing elit.[/b] Mauris tempor. Donec mollis suscipit arcu. Vestibulum.

 

To this:

 

<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Mauris tempor. Donec mollis suscipit arcu. Vestibulum.</p>

<p>[b]Lorem ipsum dolor sit amet, consectetuer adipiscing elit.[/b] Mauris tempor. Donec mollis suscipit arcu. Vestibulum.</p>

 

I think I can figure out how to turn the [ b ] into <b> using Regex.

Link to comment
Share on other sites

Usually CMS templating systems such as this evolve into something more complex than the example, do you have plans to support [img...] [url...] tags etc.?

 

For your original question:

$str=preg_replace('/^[^\r\n]+/m','<p>$0</p>',$str);

 

URL tags yes, but Img tags no. Thanks for the code.

Link to comment
Share on other sites

For the image tags it would be formatted like so:

 

file.jpg

 

the img_id of 7 corresponds to an image path like so:

 

<img alt="" src="path/to/file.jpg" />

 

Here's an example of before and after:

 

[b]Lorem ipsum dolor sit amet[/b], consectetuer adipiscing elit. Sed sapien felis, feugiat et, porta nec.

[i][b]Lorem ipsum dolor sit amet[/b], consectetuer[/i] adipiscing elit. Sed sapien felis, feugiat et, porta nec.

[img src="path/to/file.jpg"]

 

To:

 

<p><b>Lorem ipsum dolor sit amet</b>, consectetuer adipiscing elit. Sed sapien felis, feugiat et, porta nec.</p>

<p><i><b>Lorem ipsum dolor sit amet</b>, consectetuer</i> adipiscing elit. Sed sapien felis, feugiat et, porta nec.</p>

<img alt="" src="path/to/file.jpg" />

 

The guy won't know if I'm using someone else's code, so if you know of an already made bb code parser that would be great.

Link to comment
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.