tags:

views:

32

answers:

2
$var = '<img src="http://site.com/some_directory/filename.png"/&gt;';

png can be replaced with any extension.

How to cut everything, except "filename" part?

And write into new variable. In this case:

$name = 'filename';

One more example:

$var = '<img src="http://site.com/directory/subdirectory/Pakahontos.txt"/&gt;';
$name = 'Pakahontos';

Thanks.

+3  A: 
preg_match('#([^/]+)\.\w+"#', $var, $matches);
$name = $matches[1];

Note that if $var is actually more complicated (e.g. has arbitrary HTML), you must use other methods (see e.g. DOMDocument).

Artefacto
This doesn't work
Happy
@Ignatz It does. See here: http://codepad.viper-7.com/fKIRG5
Artefacto
A: 

Here's a basic HTML-parsing tutorial with preg_match. It's parsing images in the example.

fabrik