little problem
Posted: Fri Jan 26, 2007 12:02 am
I have two regular Expression
Actually i have write a small program which read a HTML file. And locate the all <img> tags in it
To locate the <img> tags, The first regular expresson is used.
And to replace the path found in <img> tag, i used the second regular expression.
which is $replace = '<img src=images_test/'.'$1';
Here see the last part of the expression: '$1'
in it all file paths are saved, which can be found while reading the file.
like it contains
/cleb/picture.jpg
/admin/abc.jpg
/cre/pic3.jpg
This thing creates a little problem for me.
In '$1'I just want filenames, like 'picture.jpg', 'abc.jpg', 'pic3.jpg' instead of the whole path as
/cleb/picture.jpg
/admin/abc.jpg
/cre/pic3.jpg
i use the basename functions in second regular expression and also try my best to got the desired output, but i am failed.
Kindly guide that how can i modify the second regular expression, so that it only contains filenames.
Thanks
Please help me in this regard.
Code: Select all
$pattern = '!<img src="([^"]+)"!';
$replace = '<img src=images_test/'.'$1';
To locate the <img> tags, The first regular expresson is used.
And to replace the path found in <img> tag, i used the second regular expression.
which is $replace = '<img src=images_test/'.'$1';
Here see the last part of the expression: '$1'
in it all file paths are saved, which can be found while reading the file.
like it contains
/cleb/picture.jpg
/admin/abc.jpg
/cre/pic3.jpg
This thing creates a little problem for me.
In '$1'I just want filenames, like 'picture.jpg', 'abc.jpg', 'pic3.jpg' instead of the whole path as
/cleb/picture.jpg
/admin/abc.jpg
/cre/pic3.jpg
i use the basename functions in second regular expression and also try my best to got the desired output, but i am failed.
Kindly guide that how can i modify the second regular expression, so that it only contains filenames.
Thanks
Please help me in this regard.