[thelist] regular expression help
Bob Meetin
ontheroad at frii.com
Sun Apr 1 12:05:50 CDT 2007
I'm back... I tested and can't seem to get it to work, so I created a
test page in PHP. The page is at www.dottedi.biz/codesamples/regex.php.
On the page I display the code in plain text, then have a section to
display the output. I made up some dummy contents for the variable,
$data.
What this is for - I have some content management pages where clients
can update some of their own content. I'm trying to make it a little
easier for them to do a few very simple functions such as include a URL
without having to know HTML. This is similar in concept to some of the
bbcode stuff I've seen on a few message boards.
BTW - I took a look at tinyMCE and some of the other text editors that
were emailed out on another thread- it does some nice things and I found
the manual helpful enough to be able to fairly painlessly add/remove
formatting functions. The ultimate goal is to be able to offer clients
four or five different textarea formatting options depending on their
comfort level (as well as limiting/controlling the content itself).
Another variation to bbcode which I also like is the one where you can
highlight some text, select a formatting function and it inserts the
bbcode into the textarea body.
Over, Bob
misterhaan wrote:
> how about this:
>
> if(preg_match('/(\{[^\}]\})(.+?)(\{\/[^\}]\})/', $data, $matches)) {
> $contents = $matches[2];
> $data = str_replace($matches[0], $matches[1] . $matches[3], $data);
> }
>
>
> that should pull out the contents into $contents and remove it from
> $data, but keep the delimiters. i didn't test it, and it will only do
> it once so if you have more than one delimiter you'd need to loop
> instead of using if, and probably store $contents a different way.
>
More information about the thelist
mailing list