preg match all - Php preg_match_all, wordpress function -


i have found code on internet...i'm don't know php... can tech me,pleasee..

<?php function catch_that_image() {   global $post, $posts;   $first_img = '';   ob_start();   ob_end_clean();   $output = preg_match_all('<img.+src=[\'"]([^\'"]+)[\'"].*>', $post->post_content, $matches);   $first_img = $matches [1] [0];    if(empty($first_img)){ //defines default image     $first_img = "/images/default.jpg";   }   return $first_img; } ?> 

how replace <img.+src=[\'"]([^\'"]+)[\'"].*>

if want take word after "=" , before "]" text:

[image name=ubuntustudio-tribal-54]  or [image name=office-tool] or  [image name=car]  or  [image name=158] 

i want output take "a-z or symbol or number" after "=" , before "]"

thanks

the code found on internet kind of irrelevant. in order achieve want need this:

$str = "[image name=ubuntustudio-tribal-54] "; $pat = "~\[image name=([^\]]+)~i"; preg_match($pat, $str, $matches); $name = $matches[1]; 

after $name bound ubuntustudio-tribal-54.

see docs more details regarding php's preg_match.
see also, great source of info regular expressions in general.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -