Hello, this is a url as below which exists in my mysql database in a particular field ecx.images-amazon.com/images/I/41ucO6VO9TL._SL500_AA300_.jpg you can see this below portion in the above url 41ucO6VO9TL. I want to select and retrieve only 41ucO6VO9TL. from the url in the mysql database (ecx.images-amazon.com/images/I/41ucO6VO9TL._SL500_AA300_.jpg) I don't want to retrieve the whole url Any help regarding this would be greatly appreciated. Thanks!
What Thibaut wrote is correct but besides that doesn't help much. For this particular problem you will need to call the explode function twice. The parameters it takes are the delimiter by which you want to split the string, and the string in question. First you would need to split it by "/" like so: $pieces = explode("/", "ecx.images-amazon.com/images/I/41ucO6VO9TL._SL500_AA300_.jpg"); Code (markup): Then you would need to get the last element of the array $pieces which given that you always have 3 "/" will be the 4th element, after which you split it again by "_" and your first element in the array is the string in question you want: $pieces = explode("_", $pieces[3]); $result = $pieces[0]; Code (markup): Now $result will have the value of 41ucO6VO9TL. in this particular case.