[PHP] Replacing text on page, but not in img tags

2003-11-06 Thread Taylor York
Lets say im trying to replace every occurance of 'hello' with 'bhi/b'.
heres a sample page
html
  hello there!
/html

This would simply change to
html
  bhi/b there!
/html

but what if it had an img?
html
  hello there!
  img src=hello.jpg alt=well hello there
/html

It would then be,
html
  bhi/b there!
  img src=bhi/b.jpg alt=well bhi/b there
/html

It would then be completely jacked up. Not only would it do the wrong img,
but the tag in general would be screwed be cause of the bold tag.  So what
can I do?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Replacing text on page, but not in img tags

2003-11-06 Thread Jay Blanchard
[snip]
It would then be completely jacked up. Not only would it do the wrong
img,
but the tag in general would be screwed be cause of the bold tag.  So
what
can I do?
[/snip]

Skip the image tag by using regex.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Replacing text on page, but not in img tags

2003-11-06 Thread Taylor York
Ya, i know it will be done with regular expressions, but how?
I dont know how to format that kind of expression


[snip]
It would then be completely jacked up. Not only would it do the wrong
img,
but the tag in general would be screwed be cause of the bold tag.  So
what
can I do?
[/snip]

Skip the image tag by using regex.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Replacing text on page, but not in img tags

2003-11-06 Thread John W. Holmes
Taylor York wrote:

Lets say im trying to replace every occurance of 'hello' with 'bhi/b'.
Here's something that's probably close to what you want. Something else 
you need to worry about besides img tags is what if the word hello 
appears in a a tag? within Javascript?

This will match anything outside of tags, at least, and then add in the 
strong tags around hello.

function callback($match)
{ return str_replace('hello','stronghello/strong',$match[0]); }
$new_str = preg_replace_callback('/([^]+)/','callback',$str);

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php