Solved

Simple regex not working

Posted on 2007-03-26
3
260 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
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.

679 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