jordanwb Posted November 21, 2008 Share Posted November 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/133649-wrapping-paragraph-tags-around-text/ Share on other sites More sharing options...
ddrudik Posted November 21, 2008 Share Posted November 21, 2008 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); Quote Link to comment https://forums.phpfreaks.com/topic/133649-wrapping-paragraph-tags-around-text/#findComment-695355 Share on other sites More sharing options...
jordanwb Posted November 21, 2008 Author Share Posted November 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/133649-wrapping-paragraph-tags-around-text/#findComment-695366 Share on other sites More sharing options...
jordanwb Posted November 21, 2008 Author Share Posted November 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/133649-wrapping-paragraph-tags-around-text/#findComment-695541 Share on other sites More sharing options...
ddrudik Posted November 21, 2008 Share Posted November 21, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/133649-wrapping-paragraph-tags-around-text/#findComment-695549 Share on other sites More sharing options...
jordanwb Posted November 21, 2008 Author Share Posted November 21, 2008 For the image tags it would be formatted like so: 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. Quote Link to comment https://forums.phpfreaks.com/topic/133649-wrapping-paragraph-tags-around-text/#findComment-695569 Share on other sites More sharing options...
jordanwb Posted November 21, 2008 Author Share Posted November 21, 2008 I found this one: http://www.webtech101.com/PHP/simple-bb-code which looks simple enough. I'll give that a try. Quote Link to comment https://forums.phpfreaks.com/topic/133649-wrapping-paragraph-tags-around-text/#findComment-695578 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.