/ Published in: PHP
Find The Image
In pseudo code, what we need to do is:
- get the post content
- Use regex to find all images
- loop through all images and check if they are valid
Expand |
Embed | Plain Text
// get post content global $post; $content = $post->post_content; // set default image value $theImageSrc = ''; // regex to find all images // needs to be a loop // Notice the += 2 in the for iterator // 0 = full image html tag // 1 = image path selected if ($imageCount >= 1) { for ($i = 1; $i <= $imageCount; $i += 2) { $theImageSrc = $matches[$i][0]; break; } } }
You need to login to post a comment.
