PluginProbe
Depicter — Popup & Slider Builder / 1.2.0
Depicter — Popup & Slider Builder v1.2.0
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / vendor / averta / wordpress / src / Utility / Extract.php

Extract.php in Depicter — Popup & Slider Builder 1.2.0, at vendor/averta/wordpress/src/Utility/Extract.php

48 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Averta\WordPress\Utility;
3
4
5 class Extract
6 {
7 /**
8 * Extract all images from content
9 *
10 * @param string $text The text to extract images from.
11 *
12 * @return bool|array List of images in array
13 */
14 public static function imagesFromText( $text )
15 {
16 preg_match_all( '|<img.*?src=[\'"](.*?)[\'"].*?>|i', $text, $matches );
17 return isset( $matches ) && count( $matches[0] ) ? $matches : false;
18 }
19
20 /**
21 * Get first image src from content
22 *
23 * @param string $text The content to extract image from.
24 *
25 * @return string First image URL on success and empty string if nothing found
26 */
27 public static function firstImageSrcFromText( $text )
28 {
29 $images = self::imagesFromText( $text );
30
31 return ( $images && count( $images[1]) ) ? $images[1][0] : '';
32 }
33
34 /**
35 * Get first image tag from string
36 *
37 * @param string $text The text to extract image from.
38 *
39 * @return string First image tag on success and empty string if nothing found
40 */
41 public static function firstImageFromText( $text )
42 {
43 $images = self::imagesFromText( $text );
44
45 return ( $images && count( $images[0]) ) ? $images[0][0] : '';
46 }
47 }
48