I'm working with this 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 the numeric ID and gives me 415321306.
So my question is how can I do the same thing but using PHP.
Best regards.
Who needs regex?
<?php
$sURL = "http://itunes.apple.com/us/app/accenture-application-for/id415321306?uo=2&mt=8&uo=2";
$appID = str_replace('id','',basename(parse_url($sURL, PHP_URL_PATH)));
echo $appID; // output: 415321306
?>
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 a little unclear on what you're doing with the length of the string, but you can get substrings in php with substr().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With