I have a string:

...<a href="http://mple.com/nCCK8.png">...

From this I am trying to strip out the

"nCCK8.png" part

I tried substr, but that requires 2 numbers and didn't work as it can be in different positions in the string. It does occur only once in the string.

The base string always has mple.com/ before the nCCK8.png part, and always "> after.

What is the easiest way to do this?


You need preg_match()

Written by jakenoble

have you heard about explode function? $var1 = explode('/',$var); and then echo $var1[0] $var1[1] $var1[2] $var1[3]; to show the contents

Written by Fernando Costa

Accepted Answer


$_ = null;
if (preg_match('/([^\/]+?\.png)/i',$data,$_)){
  echo $_[1];

Working Demo: http://www.ideone.com/3IkhB

Written by Brad Christie
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki