How can I get a part of a string from the specific starting position to end. Like for example I want to copy B000ROAQ30 from the given url:
www.amazon.com/Black-Nokia-HS-47-Stereo-Headset/dp/B000ROAQ30/ref=pd_sim_hi_4
This B000ROAQ30 part can occour anywhere in the URL like in this case:
www.amazon.com/abc/cdfg/hij/dp/B000ROAQ30/ref=pd_sim_hi_4
How can I copy this B000ROAQ30?
Note B000ROAQ30 can be different but having B00 at the start.
Please ask questions if anything is not clear.
This should work:
$url = 'www.amazon.com/Black-Nokia-HS-47-Stereo-Headset/dp/B000ROAQ30/ref=pd_sim_hi_4';
preg_match('/B00[0-9A-Z]+/', $url, $matches);
$result = $matches[0];
$result in this case will be: B000ROAQ30. Check it here: http://ideone.com/XrjIG
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