Solved

issue with regular expressions

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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 look for a specific file type in a local or remote server directory using PHP.
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…

746 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

9 Experts available now in Live!

Get 1:1 Help Now