Please login or register.

Login with username, password and session length
Advanced search  

News:

Get quality web hosting, virtual private servers, reseller web hosting, and dedicated servers from www.webhostfreaks.com or www.serverpowered.com!

Author Topic: Wrapping paragraph tags around text  (Read 292 times)

Active users: jordanwb (5), ddrudik (2)
0 Members and 1 Guest are viewing this topic.

jordanwb

  • Devotee
  • Offline Offline
  • Gender: Male
  • Posts: 525
  • Don't mess with sound
    • View Profile
Wrapping paragraph tags around text
« on: November 21, 2008, 09:16:33 AM »
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:

Code: [Select]
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:

Code: [Select]
<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.
Logged
You have the right to remain silent. Anything you say can and will be misquoted and used against you.

ddrudik

  • Enthusiast
  • Offline Offline
  • Posts: 78
    • View Profile
    • WWW
Re: Wrapping paragraph tags around text
« Reply #1 on: November 21, 2008, 09:59:09 AM »
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:
Code: [Select]
$str=preg_replace('/^[^\r\n]+/m','<p>$0</p>',$str);
« Last Edit: November 21, 2008, 10:02:39 AM by ddrudik »
Logged

jordanwb

  • Devotee
  • Offline Offline
  • Gender: Male
  • Posts: 525
  • Don't mess with sound
    • View Profile
Re: Wrapping paragraph tags around text
« Reply #2 on: November 21, 2008, 10:07:10 AM »
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:
Code: [Select]
$str=preg_replace('/^[^\r\n]+/m','<p>$0</p>',$str);

URL tags yes, but Img tags no. Thanks for the code.
« Last Edit: November 21, 2008, 10:12:13 AM by jordanwb »
Logged
You have the right to remain silent. Anything you say can and will be misquoted and used against you.

jordanwb

  • Devotee
  • Offline Offline
  • Gender: Male
  • Posts: 525
  • Don't mess with sound
    • View Profile
Re: Wrapping paragraph tags around text
« Reply #3 on: November 21, 2008, 12:14:54 PM »
do you have plans to support [img...] [url...] tags etc.?

I think I may support Image tags, some tags would be easier to replace than others such as <b> and <i>. I want to have <a> tags as well.
Logged
You have the right to remain silent. Anything you say can and will be misquoted and used against you.

ddrudik

  • Enthusiast
  • Offline Offline
  • Posts: 78
    • View Profile
    • WWW
Re: Wrapping paragraph tags around text
« Reply #4 on: November 21, 2008, 12:25:29 PM »
As for how to handle the other tags, consider similar questions here to handle those as well as what to do with mismatched tags etc.:
http://regexadvice.com/forums/thread/45583.aspx
http://regexadvice.com/forums/thread/46297.aspx
Logged

jordanwb

  • Devotee
  • Offline Offline
  • Gender: Male
  • Posts: 525
  • Don't mess with sound
    • View Profile
Re: Wrapping paragraph tags around text
« Reply #5 on: November 21, 2008, 12:54:21 PM »
For the image tags it would be formatted like so:

[img src="path/to/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:

Code: [Select]
[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:

Code: [Select]
<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.
« Last Edit: November 21, 2008, 01:01:59 PM by jordanwb »
Logged
You have the right to remain silent. Anything you say can and will be misquoted and used against you.

jordanwb

  • Devotee
  • Offline Offline
  • Gender: Male
  • Posts: 525
  • Don't mess with sound
    • View Profile
Re: Wrapping paragraph tags around text
« Reply #6 on: November 21, 2008, 01:08:50 PM »
I found this one: http://www.webtech101.com/PHP/simple-bb-code which looks simple enough. I'll give that a try.
Logged
You have the right to remain silent. Anything you say can and will be misquoted and used against you.

PHP Freaks Forums

 
 
 

Page created in 0.05 seconds with 21 queries.