I'm looking for a script like this, but no matches have been found so far.
I know that you are the people here, think about the box, so I ask you.
I have to check (with PHP) that if a specific word in my string is looking for an example in my Alt tag if I'm searching for the word gem and my string Is:
I have a gem & lt; Img src = "whatever.jpg" alt = "this is my gem" & gt; You are good
It will only tell me that I have a true match, because the gem is in my Alt tag and so there is a match. There will be a wrong match:
I have a gem; IG src = "whatever.jpg" alt = "this is my gem" & gt; You are good
Because I'm searching for the word gem in the Alt tag. Hope someone can help me.
To expand the annotations, here's a way you can see the DOMDocument
Category:
$ dom = new problem using DOMDocument (); $ Dom- & gt; Load HTML ('I have a gem & lt; img src = "whatever.jpg" alt = "this is my gem" & gt; you are okay.); Foreign currency ($ dom-> getElementsByTagName ($ as img) {$ alt = $ img-> getAttribute ('alt'); if (preg_match ('/ \ bgem \ b /', $ alt) ) {Resonant "matching: $ alt";}}
This string is used as HTML and loops as both of the element
elements Parsing This word uses a regular expression with the word boundaries \ b
to match the events of "gem".
Output:
Pre class = "lang-none prettyprint-override"> this is my gem
No comments:
Post a Comment