PHP equivalent to JavaScript's string split method -


i'm working on javascript:

<script type="text/javascript">     var surl = "http://itunes.apple.com/us/app/accenture-application-for/id415321306?uo=2&mt=8&uo=2";     spliturl = surl.split('/');     var appid = spliturl[spliturl.length - 1].match(/[0-9]*[0-9]/)[0];     document.write('<br /><strong>link lookup:</strong> <a href="http://ax.itunes.apple.com/webobjects/mzstoreservices.woa/wa/wslookup?id=' + appid + '&country=es" >lookup</a><br />'); </script> 

this script takes numeric id , gives me 415321306.

so question how can same thing using php.

best regards.

use php's explode() function instead of .split().

spliturl = surl.split('/');  //javascript 

becomes

$spliturl = explode('/', $surl);  //php 

an use preg_match() instead of .match().

$appid = preg_match("[0-9]*[0-9]", $spliturl); 

i'm little unclear on you're doing length of string, can substrings in php substr().


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -