phpstripos

Filter a string in PHP


I'm looking to get an array of ID's from the following string.

[vc_gallery type="flexslider_fade" interval="3" images="3057,2141,234" onclick="link_image" custom_links_target="_self" img_size="large"]

Ideally, i'd like to look at this string and get an array of the INT values within images. e.g.

array("3057", "2141", "234");


Solution

  • find images value and explode it to receive array

    $str = '[vc_gallery type="flexslider_fade" interval="3" images="3057,2141,234" onclick="link_image" custom_links_target="_self" img_size="large"]';
    
    if (preg_match('/images\s*=\s*\"([^\"]+)\"/', $str, $m)) {
       $res = explode(',', $m[1]);
       print_r($res);
    }