Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Simple regex not working

Posted on 2007-03-26
3
Medium Priority
?
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 22

Accepted Solution

by:
Ivo Stoykov earned 2000 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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 four methods for overlaying images in a container on a web page
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.

704 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