我有一块html存储在wordpress的自定义字段中。我需要使用php函数仅返回来自该自定义字段的链接。它必须是一个功能。这是我的尝试,但我的结果只是说阵列:PHP函数返回html中的链接
<?php
function linkExtractor($html){
$linkArray = array();
if(preg_match_all('/<img\s+.*?src=[\"\']?([^\"\' >]*)[\"\']? [^>]*>/i',$html,$matches,PREG_SET_ORDER)){
foreach($matches as $match){
array_push($linkArray,array($match[1],$match[2]));
}
}
return $linkArray;
}
?>
在wordpress中,我用它作为短代码,它看起来像。这是100%正确的格式,因为我一直都在使用它。
[linkExtractor(custom_field_name)]
我厌倦了这两个功能linkExtractor()和功能linkExtractor($ HTML) –
即使语法是有点不同的,也许我的简码库会派上用场:https://开头github上。 com/thunderer/Shortcode。 –