Solved

issue with regular expressions

Posted on 2006-07-15
2
179 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now