Solved

Simple regex not working

Posted on 2007-03-26
3
238 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

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

Title # Comments Views Activity
<? versus <?php 5 38
xampp tool 12 31
PHPStorm debugging issues 1 26
Wordpress errors showing up, hacked? 4 17
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…
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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