Solved

issue with regular expressions

Posted on 2006-07-15
2
180 Views
Last Modified: 2006-11-18
I am parsing some text that looks like this:


the girl's name is [[child_name]], and her brother's name is [[brother_name]]. They went to the park.

I'm using this:
      $text = preg_replace("/\[\[(.*)\]\]/","<input type=\"text\" name=\"$1\" value=\"$1\" onfocus=\"this.value='';\">",$text);

So the desired effect is:
The girl's name is <input type="text" name=\"child_name" value="child_name">.  

But what I'm getting is
The girls's name is <input type="text" name="child_name]], and her brother's name is [[brother_name" value="child_name]], and her brother's name is [[brother_name">

Any ideas why this is happening?

Thanks for your help.
0
Comment
Question by:bandyell
2 Comments
 
LVL 9

Accepted Solution

by:
tolgaong earned 250 total points
ID: 17115744
$text= preg_replace('/\\[\\[(.*?)\\]\\]/', "<input type=\\\"text\\\" name=\\\"$1\\\" value=\\\"$1\\\" onfocus=\\\"this.value='';\\\">", $text);
0
 

Author Comment

by:bandyell
ID: 17115820
wonderful, thanks.  Regular expressions has always been my weak point.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question