Automattic\WooCommerce\EmailEditor\Integrations\Utils

Html_Processing_Helper::extract_url_from_textpublic staticWC 1.0

Extract the first HTTP/HTTPS URL from a text string.

Method of the class: Html_Processing_Helper{}

No Hooks.

Returns

String. Extracted URL or empty string if not found.

Usage

$result = Html_Processing_Helper::extract_url_from_text( $text ): string;
$text(string) (required)
Text to search for URLs.

Html_Processing_Helper::extract_url_from_text() code WC 10.7.0

public static function extract_url_from_text( string $text ): string {
	if ( preg_match( '/(?<![a-zA-Z0-9.-])https?:\/\/[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}[a-zA-Z0-9\/?=&%_.~+#-]*(?![a-zA-Z0-9._~+#-])/', $text, $matches ) ) {
		return $matches[0];
	}

	return '';
}