php - How to ignore character case of attribute's value? -



php - How to ignore character case of attribute's value? -

i'm using curl fetch meta description of web page. here's fraction of code:

$metas = $doc->getelementsbytagname('meta'); ($i = 0; $i < $metas->length; $i++) { $meta = $metas->item($i); $metaname = $meta->getattribute('name'); if($metaname == 'description') $description = $meta->getattribute('content'); } <meta name="description" content="<?php echo $description; ?>" />

it works ok, not perfectly. problem happens when character case of element's attribute or value different defined. example, code above not output content values if meta attribute "name" or value "description" uppercase(name,description) or capitalized(name,description).

how work around without much codes?

you can seek php's strcasecmp()

example

if (strcasecmp($metaname, 'description') == 0) { //equals }

and, according this answer, strcasecmp() , strtolower() approaches o(n) in speed using strtolower() allocates new string hold result in turn increases memory pressure level , reduces performance

php doc

php xmldom

Comments

Popular posts from this blog

c - Compilation of a code: unkown type name string -

java - Bypassing "final local variable defined in an enclosing type" -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -