Help with preg_match

Reply

Join Date: Sep 2008
Posts: 1
Reputation: nadal is an unknown quantity at this point 
Solved Threads: 0
nadal nadal is offline Offline
Newbie Poster

Help with preg_match

 
0
  #1
Sep 4th, 2008
Hi,
i need help with preg_match
i hawe links like
http://test.site.com/cat1/cat2/123.html
http://test.site.com/cat1/cat2/cat3/1.html
i need when i put on form this link and pres submit to get link to last / aded text page- get the numberof html page and change the .html in a .txt like:
http://test.site.com/cat1/cat2/page-123.txt
http://test.site.com/cat1/cat2/cat3/page-1.txt
Thanks
Sorry for bad english!!!
Last edited by nadal; Sep 4th, 2008 at 2:16 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: Help with preg_match

 
0
  #2
Sep 5th, 2008
Hi

Regular expressions are tricky and can be very picky. If you have different input structures than the ones you provided, I cannot guarantee it to work with those other structures.

Hope it helps
  1. <?php
  2. // TEST SUBJECT STRINGS
  3. $link1 = 'http://test.site.com/cat1/cat2/123.html';
  4. $link2 = 'http://test.site.com/cat1/cat2/cat3/1.html';
  5.  
  6. // find this pattern
  7. $pattern = '#^(.*/)(\d+)(\.html)$#';
  8. // make these replacements
  9. $replace = '\\1page-\\2.txt';
  10.  
  11. // regular expression preg_replace ...
  12. print preg_replace( $pattern, $replace, $link1 );
  13. print "\n<br>\n";
  14. print preg_replace( $pattern, $replace, $link2 );
  15.  
  16. /** OUTPUT OF ABOVE TESTS
  17. http://test.site.com/cat1/cat2/page-123.txt
  18. http://test.site.com/cat1/cat2/cat3/page-1.txt
  19. **/
  20. ?>
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC