Ok, i know there are trillions of similar questions, but i'm finding it really hard to achieve this. I have some strings of this formats:
$x = '<iframe src="[File:19]"></iframe>';
$y = '<img src=[File:2212] />';
$z = '<source src="[File:42]" />';
I'm trying to get the id given after the File:
and also replace the whole [File:xxx]
with another string. I'm trying like the following, but it seems i can't fully understand the usage of preg_replace.
$file = ('<iframe src="[File:134]"></frame>');
$rex = "/^.*(\[File:[0-9]{1,}\])/i" ;
if ( preg_match($rex, $file, $match) ) {
echo 'OK';
}
$file = preg_replace ($rex, "http://lala.com/la.pdf", $file);
echo "<br>".htmlentities($file)."<br>";
Could you please give me some hints on how i can do this?
Thanks in advance.
preg_match_all
and delete^.*
.. (should work) But actually you should use PHP DOM for this – mash Mar 13 '12 at 14:17