|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today! |
|
#1
|
|||
|
|||
|
Regular expressions and HTML Links
I'm posting a url such as....
http://somewhere.com/link.php?id=2 from a TEXTBOX to my page as the variable name HTMLLinkToReplace called using $HTTP_POST_VARS[HTMLLinkToReplace] However I'm also posting HTML code from a TEXTAREA with the variable name HTMLCode called using $HTTP_POST_VARS[HTMLCode] ____SNIPIT OF HTML CODE BEING POSTED____ [ - Being posted as TEXTAREA named HTMLCode - ] <b>Some HTML</b><br> <u>Some more HTML</u> <a href="http://somewhere.com/link.php?id=2">A Link</a><br> <a href="http://somewhere.com/link2.php?id=5">Another Link</a><br> <a href="http://somewhere.com/link.php?id=2">A second link that shouldn't match the regular expression</a> ____ //END HTML CODE SNIPIT//_____ What I'm trying to do is replace the first link that matches $HTTP_POST_VARS[HTMLLinkToReplace] with the preg_replace() function. The reason I choose this function is to replace ONLY the first instance of http://somewhere.com/link.php?id=2 in the $HTTP_POST_VARS[HTMLCode] variable because it has the limit feature. I thought I might have to use quotemeta to put a before all the .'s and the ?'s in the html link before I can use the string in the preg_replace() function, but I just seem to be lost in the fact that every regular expression I try comes nowhere close to working. I simple want to echo the HTMLCode with the first link that matches HTMLLinkToReplace ... replaced. Please post replies if I am not explaining myself correctly and how I can better explain. Sorry for the length, Charles |
|
#2
|
|||
|
|||
|
RE: Regular expressions and HTML Links
Try this..
[CODE]preg_replace ( "http://somewhere.com/link.php?id=2", "http://anotherlink.com", stripslashes($textarea),1);[/highlight] The main problem I think you might be having is that php automatically adds slashes to any posted values. |
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > Regular expressions and HTML Links |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|