Solved

issue with regular expressions

Posted on 2006-07-15
2
186 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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…

696 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