Jump to content

Forum


computerpros

Recommended Posts

[!--quoteo(post=359490:date=Mar 28 2006, 05:44 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Mar 28 2006, 05:44 PM) [snapback]359490[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Bit of java script to put the code in the text box (so its user friendly!)

store that directly in your database then when outputting content to the screen do a regular expression replacement of the tags for your html tags.
[/quote]
Could you explain that regular expression replacement stuff to me some more or point to a tut please?
-Computerpros
Link to comment
Share on other sites

quickie...

OK you have doen teh javascript to place stuff like [b]BOLD[/b],[h1]Header[/h1] into the text area adn teh the whole string has been saved in the database.

You want to replace [b]SOME TEXT[/b] with bold tags adn same for h1

now you could do a string replace on just the '[' and the ']'
[code]<?php
$string = "[b]some bold text[/b] at the start of teh post.";

$lookfor = array('[', ']');
$replacewith = array('<', '>');
$string = str_replace($lookfor, $replacewith, $string);
?>
[/code]
or you could do similar with regular expressions...
[code]<?php
$lookfor = array('/[b](?!\[)[/b]/','/[h1](?!\[)[/h1]/');
$replacewith = array('<b>\\1</b>', '<h1>\\1</h1>');
$strinng = preg_replace($lookfor, $replacewith, $string);
?>
[/code]

It takes too long to explain regular expressions so juts go and find a good tutorial on them.....
Link to comment
Share on other sites

[!--quoteo(post=359494:date=Mar 28 2006, 05:55 PM:name=ToonMariner)--][div class=\'quotetop\']QUOTE(ToonMariner @ Mar 28 2006, 05:55 PM) [snapback]359494[/snapback][/div][div class=\'quotemain\'][!--quotec--]
quickie...

OK you have doen teh javascript to place stuff like [b]BOLD[/b],[h1]Header[/h1] into the text area adn teh the whole string has been saved in the database.

You want to replace [b]SOME TEXT[/b] with bold tags adn same for h1

now you could do a string replace on just the '[' and the ']'
[code]<?php
$string = "[b]some bold text[/b] at the start of teh post.";

$lookfor = array('[', ']');
$replacewith = array('<', '>');
$string = str_replace($lookfor, $replacewith, $string);
?>
[/code]
or you could do similar with regular expressions...
[code]<?php
$lookfor = array('/[b](?!\[)[/b]/','/[h1](?!\[)[/h1]/');
$replacewith = array('<b>\\1</b>', '<h1>\\1</h1>');
$strinng = preg_replace($lookfor, $replacewith, $string);
?>
[/code]

It takes too long to explain regular expressions so juts go and find a good tutorial on them.....
[/quote]
Ok. That will do. Thank you!
-Computerpros
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.