Monday, January 19, 2009

Extract src from IMG tag using regular expression

Here is the code to extract src from IMG tag using regular expression. We can use this also in drupal
------------------------------------------------------------------------------------
<?php
$field_lead_image_fid = '<img src="src.jpg" alt="Get groomed for the industry" title="title" />';
$epression = "/<img src=\"(.*)\" alt=\"(.*)\" title=\"(.*)\" \/>/";
preg_match_all($epression,$field_lead_image_fid,$matches);
echo '<pre>'; print_r($matches); echo '</pre>';
?>
----------------------------------------------------------------------------------

Note:
$epression Order [ src, alt, title] should be same as in $field_lead_image_fid.

No comments:

Post a Comment