Created
August 4, 2021 14:10
-
-
Save rocketgeek/6dffe495b6f516836dd33aa4291ab89b to your computer and use it in GitHub Desktop.
Extract "data-" attributes from WooCommerce HTML tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Extraction utility for getting attributes from HTML tag. | |
function extract_html_atts( $string, $prefix = "data-" ) { | |
$start = 0; | |
$end = 0; | |
while( strpos( $string, $prefix, $end ) ) { | |
$start = strpos( $string, $prefix, $start )+strlen( $prefix ); | |
$end = strpos( $string, '"', $start )-1; | |
$end2 = strpos( $string, '"', $end+2 ); | |
$array[ substr( $string, $start, $end-$start ) ] = substr( $string, $end+2, $end2-$end-2 ); | |
} | |
return $array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment