PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old September 7th, 2002, 08:44 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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


Reply With Quote
  #2  
Old September 8th, 2002, 03:14 PM
jv jv is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 jv User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Regular expressions and HTML Links


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway