arrays - How to search for HTML tags in multilpe strings with PHP? -
can utilize strpos()
searching html tags? seems produce invalid results. tried converting htmlentities()
-- still no luck. how can search text decorations like: bold, italics, , underline?
example: (demo)
/* html tags search for. */ $html_tags = array( 'bold' => array( 'before' => '<strong>', 'after' => '</strong>' ), 'italics' => array( 'before' => '<em>', 'after' => '</em>' ), 'underline' => array( 'before' => '<span style="text-decoration: underline;">', 'after' => '</span>' ) ); /* sample strings... */ $html_test = array( 'bold_with_html' => '<strong>some string containing html tags.</strong>', 'italics_with_html' => '<em>some string containing html tags.</em>', 'underline_with_html' => '<span style="text-decoration: underline;">some string containing html tags.</span>', 'without_html' => 'some string containing no html tags.' ); /* check html tags. */ $results = array(); foreach($html_test $key => $value){ foreach($html_tags $decoration => $html_tag){ if(stripos($html_tag['before'], $value) !== false && strripos($html_tag['after'], $value) !== false){ $results[$key][$decoration] = 'located html: '.$decoration.'!'; } else{ $results[$key][$decoration] = 'no html located.'; } } } print_r($results);
you got order of parameters wrong stripos
, should haystack, needle...
if(stripos($value,$html_tag['before']) !== false && strripos($value,$html_tag['after']) !== false){
php arrays loops string-search
No comments:
Post a Comment