| | |
Help with preg_match
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2008
Posts: 1
Reputation:
Solved Threads: 0
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!!!
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.
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
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
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
php Syntax (Toggle Plain Text)
<?php // TEST SUBJECT STRINGS $link1 = 'http://test.site.com/cat1/cat2/123.html'; $link2 = 'http://test.site.com/cat1/cat2/cat3/1.html'; // find this pattern $pattern = '#^(.*/)(\d+)(\.html)$#'; // make these replacements $replace = '\\1page-\\2.txt'; // regular expression preg_replace ... print preg_replace( $pattern, $replace, $link1 ); print "\n<br>\n"; print preg_replace( $pattern, $replace, $link2 ); /** OUTPUT OF ABOVE TESTS http://test.site.com/cat1/cat2/page-123.txt http://test.site.com/cat1/cat2/cat3/page-1.txt **/ ?>
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
![]() |
Similar Threads
- preg_match validation help please (PHP)
- preg_match validation (PHP)
- strpos vs. preg_match (PHP)
- Need help with this preg_match expression please (PHP)
- "preg_match" For What purpose this command use? (PHP)
Other Threads in the PHP Forum
- Previous Thread: Serching an excel sheet?
- Next Thread: Specifying page title while using this script.. :(
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend





