Reputation: 67
I have PHP variable that contains string like:
http://domain.com/uploads/image1.jpg|||http://domain.com/uploads/image2.jpg|||http://domain.com/uploads/image3.jpg|||...
I need to get first one image url from that string, so it will be string until first "|||" characters. So result i need to get into variable is: http://domain.com/uploads/image1.jpg
Please help me to write correct PHP preg_match regexp pattern for it.
Thank you! Tim
Upvotes: 2
Views: 102
Reputation: 225085
You can use substr
:
$pos = strpos($str, "|||");
$firstUrl = substr($myString, 0, $pos ? $pos : strlen($myString));
Upvotes: 2
Reputation: 838796
This should work:
'/(.*?)\|\|\|/'
You could also use expode
:
$result = explode('|||', $s, 2);
echo $result[0];
Result:
http://domain.com/uploads/image1.jpg
See it working online: ideone
Upvotes: 5