Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How search the output only `-` in any DOM using PHP script?

Tags:

dom

css

php

output

How search the output only - if any DOM as below?

  1. <p>-</p>
  2. <p><span style="font-size: medium;">-</span></p>
  3. etc.

Currently I just use the codes as below to find this output - :

$input = `<p>-</p>`;
if($input == `<p>-</p>`):
   return true;
else:
   return false;
endif;

Any better ideas?

like image 417
Nere Avatar asked Jun 08 '15 02:06

Nere


2 Answers

The accepted answer would not work for special cases like if the tag attribute values contains >-< or if - is not wrapped within the tags:

$input = '<span title="A valid title >-<">Should NOT match</span>';
$input = '<span>Should match</span>-';

Instead you could use strip_tags(), which is not as efficient as strpos() but would work for all cases:

return (strip_tags($input) === '-');
like image 98
Ulver Avatar answered Sep 28 '22 19:09

Ulver


try

$input = `<p>-</p>`;
$input = `<p><span style="font-size: medium;">-</span></p>`;
$input = `<p><div>-</div>`;
if(strpos($input, '>-<')):
   return true;
else:
   return false;
endif;
like image 30
Josua Marcel C Avatar answered Sep 28 '22 20:09

Josua Marcel C