Return the first word in the image name I just want to return the first word in the image name (before the dash, dog in my example). Now I use it like this but believe it can be done in a simpler way (like one line of code):

$live_site_image = "http://example.net/wp-content/themes/example/images/dog-in-park.jpg";
$live_site_image = substr( strrchr( $live_site_image, '/' ), 1);
$live_site_image = strtok($live_site_image,"-");
If you want to capture part of a pattern,
you can use preg_match, and surround the pattern you want to capture in (...),
like this:

$live_site_image = "http://example.net/wp-content/themes/example/images/dog-in-park.jpg";
preg_match('/images\/([^-]+)-/', $live_site_image, $matches);
// $matches[0] will be "dog"


$matches will get filled with the content matched within each (...) in the pattern. In this case there will be one match.
The pattern I used is "images/" followed by 1 or more non-dash characters followed by a dash. I only capture the part that you want.

This is just one way to extract "dog" from your input string,
there may be a better pattern more suitable for your purpose,
depending largely on the other possible urls and parts to extract.