Reputation: 6509
I have a slightly corrupt image URL and I'd like to use PHP to crop it after the file extension to make it display correctly.
How do I change this:
http://localhost:8888/wordpress/content/uploads/gravity_forms/2-c6f73a1461e90382eb2f9f633b224c1a/2014/11/0065B3.png|:||:||:||:|188
to this:
http://localhost:8888/wordpress/content/uploads/gravity_forms/2-c6f73a1461e90382eb2f9f633b224c1a/2014/11/0065B3.png
?
Thank you :-)
Upvotes: 0
Views: 142
Reputation: 3385
For your situation the following should do it?
$clean = substr($img_url, 0, strpos($img_url, '.png|')+4);
$img_url
would be the url.
This obviously is only good if there's no possibility of .png|
appearing anywhere else in the url
UPDATE:
Or this for any file extension
$clean = preg_replace('/\|.*+/','',$url);
Upvotes: 1