i 采用<代码>preg_match_all,在座标上找到某些标记:
$str = "
Line 1: This is a string
Line 2: [img]http://placehold.it/350x150[/img] Should not be [youtube]SDeWJqKx3Y0[/youtube] included.";
preg_match_all("~[img](.+?)[/img]~i", $str, $img);
preg_match_all("~[youtube](.+?)[/youtube]~i", $str, $youtube);
foreach ($img[1] as $key => $value) {
echo <img src=" .$value. " "/> ;
}
foreach ($youtube[1] as $key => $value) {
echo <iframe width="420" height="315" src="http://www.youtube.com/embed/ .$value. " frameborder="0" allowfullscreen> </iframe> ;
}
这将完全恢复正与正确价值观相呼应的东西。
但实际想要的是将整条插法与<代码>[img]和[youline]
等标号重新编号,代之以各声明的数值:
Line 1: This is a string
Line 2: <img src="http://placehold.it/350x150" "/> Should not be <iframe width="420" height="315" src="http://www.youtube.com/embed/SDeWJqKx3Y0" frameborder="0" allowfullscreen> </iframe> included.
i m not looking for a 3rd party alternative, just plain php functions.
i mink of using preg_match
and some case
and switch
statements, but i don tred
想法?