[PHP] Re: Help with regular expresions! [ASAP]

2001-07-25 Thread maatt

$tag_name = input;
$new_class = yourclass;
eregi_replace(($tag_name), \\1 class=\$yourclass\, $yourstring);

will work for simple cases, but isn't going to give you much more power than
just applying a style to the tag iself  - 'input  { border : 1px }' say). If
the design is consistent, you can usually find longer blocks of unique text
for replacing headers, subheads, etc.

I'd run the scripts over your templates (backup first), not do output
buffering - manually tweaking a couple of exceptions is a hell of a lot
faster than building re's to catch them.

Matt

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]




[PHP] Re: Help with regular expresions! [ASAP]

2001-07-25 Thread James Holloway

Hi Peter,

You could try this:

?

$string = Blah iitalic/iinput type=\name\ Blah bbold/b;

$new_string = preg_replace(/input(.*?)/i, input\\1 class=3D,
$string);

echo $stringbrbr$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=blahinput type=file with
input type=text name=blahinput type=file class=3D

Instead of
input type=text name=blah class=3Dinput 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]