Tim
Tim

Reputation: 67

Need PHP pregmach Regexp pattern for string until "|||" characters appears

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

Answers (2)

Ry-
Ry-

Reputation: 225085

You can use substr:

$pos = strpos($str, "|||");
$firstUrl = substr($myString, 0, $pos ? $pos : strlen($myString));

http://ideone.com/LaudF

Upvotes: 2

Mark Byers
Mark Byers

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

Related Questions