Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi guys,

I have these html tags:

<input type="text" id="txtName" name="txtName" />

<textarea id="taHello" name="taHello">hello world</textarea>

which I want to replace with the following tags:

<input type="text" id="txtName" name="txtName" onClick="setName()" />

<textarea id="taHello" name="taHello" onClick="setName()">hello  

I know that it can be done by using preg_replace but I haven't really  
figured out how to use it. Any help would be greatly appreciated. Thanks in  

Re: preg_replace

Quoted text here. Click to load it

Hmm... are you trying to say that you want to add the same event
handler to all inputs and textareas, or this event handler depends on
the tag and its contents, and it's not only inputs and textareas?

Anyway, you should read about regular expressions (google search will
give you A LOT of information about them - <a href="http://">google
search about regular expressions</a>), and about preg_replace
( ). That's all you need.


Re: preg_replace

Yup, I have looked into google already. There are indeed a lot of info on  
regex but unfortunately, due to my closing project deadline, I do not have  
time to go through all of them. Therefore, I would greatly appreciate if you  
(or anyone reading this) can provide me with a slightly more comprehensive  
solution. Thanks again.

Quoted text here. Click to load it

Re: preg_replace

talented Silvertype broadcast on comp.lang.php:

Quoted text here. Click to load it

Once again, you have not made clear what the nature of your problem is.

Perl itself, not php preg_replace, is the most effective way to search and
replace in a large number of files.

Even so, you would have to define the precise conditions under which you
want the replacement made.  If you could do that, of course, your problem
would be easily solved if you consulted the manual on preg_replace.

Someone could, of course, give you function calls that would make the
replacement in the two strings you have given.  But if you really needed to
change only these two strings, you would simply make the changes with a text
editor.  Therefore, we all suppose your problem is more general (unless of
course it is homework).  Do you want to add your "onclick" event to every
input element and every textarea element?  Or are there particular
conditions on the ones you want to replace?

That returns us to the question of context.  Where are the strings coming
from?  Are you generating them?  Are they static parts of pages that also
contain php?  Are you serving the pages directly, or are you using php cli
to modify existing files?

In other words, it appears you cannot --- at least you have not --- defined
the problem.

Don't top post.

Lars Eighner     < <
                         Countdown: 444 days to go.
                    What do you do when you're debranded?

Site Timeline