Solved

Simple regex not working

Posted on 2007-03-26
3
253 Views
Last Modified: 2007-03-27
$html = "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"\">";
$html = preg_replace('/form/si', 'f1', $html);


Anyone have any idea why this isnt working?
0
Comment
Question by:fox_statton
3 Comments
 
LVL 22

Accepted Solution

by:
Ivo Stoykov earned 500 total points
ID: 18792062
Hello fox_statton,

it works for me

$html = "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"\">";
$html = preg_replace('/form/si', 'f1', $html);
print $html;

here is the output

<f1 id="f11" name="f11" method="post" action="">

Regards,

ivostoykov
0
 
LVL 48

Expert Comment

by:hernst42
ID: 18792087
If you dont want to replace the form-tag itself, only the id and name try using
$html = "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"\">";
$html = preg_replace('/form(\d+)/si', 'f\1', $html);
0
 
LVL 23

Expert Comment

by:Stacy Spear
ID: 18794190
What result are you getting and what were you expecting?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Syntax Error 4 32
How do I fix this UPDATE error? 7 32
What's wrong with this PDO query? 5 27
PHP Mail error 3 27
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

828 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