I m using the code below to extract the first image from a wordpress post function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches); $first_img = $matches [1] [0]; // no image found display default image instead if(empty($first_img)){ $first_img = "/images/default.jpg"; } $first_img = "<img src="' . $first_img . '" />"; return $first_img; } PHP: <?php echo catch_that_image() ?> PHP: The output , i m getting as <img src='http://mysiteurl.com/wp-content/upload/2011/3.gif' /> PHP: i want to change the single (') quote to double quote (") Like <img src="http://mysiteurl.com/wp-content/upload/2011/3.gif" /> PHP: How this can be achieved .. Many thanks in Advance!
I would take a look at PHP's preg_replace method. You can create a simple regex to find a URL with single quotes (if one exists) and then replace it with the appropriate double quotes. Regards, Dennis M.
You have a syntax error in $first_img = "<img src="' . $first_img . '" />"; PHP: Try this, it should work: $first_img = '<img src="' . $first_img . '" />'; PHP: