这个字符串位于哪里?我知道你写了“没有wordpress系统”,但wordpress有一个功能get shortcode regex
如果出于某种原因确实想避免,以下示例可能会帮助您:
// check the post for a short code
function check_shortcode( $shortcode = NULL ) {
$post_to_check = get_post( get_the_ID() );
// Until we search, set false
$found = false;
// no short - FALSE
if ( ! $shortcode ) {
return $found;
}
// check the post content for the short code
if ( stripos( $post_to_check->post_content, \'[\' . $shortcode) !== FALSE ) {
// we have found the short code
$found = TRUE;
}
// return our final results
return $found;
}