This is a discussion on preg_replace href question within the PHP General forums, part of the PHP Programming Forums category; Trying to rename all links like: <a name="link1" href="links.php" onmouseover="something&...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Trying to rename all links like:
<a name="link1" href="links.php" onmouseover="something"> To be: <a name="link1" href="index.php?filename=links.php" onmouseover="something"> I am using ---> $contents = preg_replace("/href=\"(.*)\"/i", "href=\"index.php?filename=\\1\"", $contents); And it is coming back: <a href="index.php?filename=links.php"onmouseover="so mething"> Not sure why the end of line is after the "<a" and no space before the "onmouseover". Can anyone help shed some light as to how to improve this? Thank you, JJ |
|
|||
|
Not sure if I am posting in the wrong forum because I haven't heard
back from a few issues. If I am, would someone please let me know? Thanks! For an update to this problem, the only problem I have now is the preg_replace seems to only be replacing the first link in my HTML string. Not sure why. Is there something that I should be looking for in the string that could be causing the replace to stop at that first find? Any help would be appreciated. Thanks! JJ jamesmgiordano@yahoo.com (Jimmy Jim) wrote in message news:<8e3d28ff.0402100836.df7129b@posting.google.c om>... > Trying to rename all links like: > > <a name="link1" href="links.php" onmouseover="something"> > > To be: > > <a name="link1" href="index.php?filename=links.php" > onmouseover="something"> > > I am using ---> > > $contents = preg_replace("/href=\"(.*)\"/i", > "href=\"index.php?filename=\\1\"", $contents); > > And it is coming back: > > <a > href="index.php?filename=links.php"onmouseover="so mething"> > > Not sure why the end of line is after the "<a" and no space before the > "onmouseover". Can anyone help shed some light as to how to improve > this? Thank you, > > JJ |