eregi_replace and regular expressions
| From: | Eric Dean | Date: | Mon, 30 Sep 2002 16:40:04 +0000 |
| Subject: | eregi_replace and regular expressions | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-118229@lists.php.net to get a copy of this message | ||
Hello all,
I am trying to add html code using php on the fly while uploading web pages
to our database. All of my replace functions seem to work well except one.
I am trying to add a <table> tag after the body tag. It is easy to find
the body tag because there is only one "<body" in an html document. I am
having a terrible time trying to find the end of the tag because it has
unknown length and contents, but it does end with a ">". So here is what
I've tried:
$filedata = eregi_replace("<body(.*)>","<body\\1><table border=0 width='80%'>",$filedata);
This line of code happily adds the <table border=0 width='80%'> at the end
of the document. eregi_replace uses a case insensitive matching. The reg
exp is matching the entire $filedata rather than stopping at the first ">"
after "<body". How do I get it to stop at the first ">" after "<body"?
What am I doing wrong?
Thank you,
--
Eric Dean eric-dean@uiowa.edu
Chief Curator, Office of Visual Materials
School of Art and Art History, University of Iowa