function get_post_1st_img ($the_content=”) {
if(strlen($the_content)) {
// use regex to find the src of the image
preg_match(“/<img src\=(‘|\”)(.*)(‘|\”) .*( |)\/>/”, $the_content, $matches);
if(!$matches) {
preg_match(“/<img class\=\”.*\” title\=\”.*\” src\=(‘|\”)(.*)(‘|\”) .*( |)\/>/U”, $the_content, $matches);
}
$the_image_src = $matches[2];
$frags = preg_split(“/(\”|’)/”, $the_image_src);
if(count($frags)) {
$the_image_src = $frags[0];
}
// if src found, then create a new img tag
// if the src starts with http/https, then strip out server name
if(strlen($the_image_src) && preg_match(“/^(http(|s):\/\/)/”, $the_image_src)) {
$the_image_src = preg_replace(“/^(http(|s):\/\/)/”, ”, $the_image_src);
$frags = split(“\/”, $the_image_src);
array_shift($frags);
$the_image_src = ‘/’ . join(“/”, $frags);
}
return $the_image_src;
}
}
this function is working,
but
img = get_post_1st_img ($_REQUEST[‘CONTENT’])
does not work in custom meta panel, Why?