Hi Peter,
You could try this:
<?
$string = "Blah <i>italic</i><input type=\"name\"> Blah <b>bold</b>";
$new_string = preg_replace("/<input(.*?)>/i", "<input\\1 class=3D>",
$string);
echo "$string<br><br>$new_string";
?>
preg_replace = regular expression replacement
<input = first part of tag
(.*?) = whatever, but not:
>
.* is greedy... Match any character . as many times * as necessary, made
less greedy because the ? looks for whatever's to the right of it.... If
you did:
preg_replace("/<input(.*)>/i", "<input\\1 class=3D>", $string);
it might replace <input type="text" name="blah"><input type="file"> with
<input type="text" name="blah"><input type="file" class=3D>
Instead of
<input type="text" name="blah" class=3D><input type="file" class=3D>
Which is what you want.
The \\1 is what you have captured from the first (and in this case, only)
set of parentheses ()
The i after the delimiter means case insensitive.
Note, I didn't have time to check that this works, but you get the principle
:)
James
"Psychosphere2k" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
Hi!
I have a fairly large PHP based website.
Unfortuantely, I didn't make extensive use of stylesheets.
I'm hoping for some help with regular expressions matching ( and =
replacing ) some tags.
I use output buffering, so it would be a simple case of adding some =
lines to my
output hanlder.
eg:
replacing < input .... > with < input .... class =3D "something " >
and < body .... > with < body .... class =3D "something_else" >
Some code, with comments would be really great.
Thanks in advance.
Peter Gibson
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]