php - echo out just first foreach array -


I am using this piece of code using simple HTML domains:

  $ Google = "http://www.google.com/something."; $ Html = file_get_html ($ google_html); Foreach ($ html-> Search ('span [class = st]') $ element) $ element-> Innertext;  

But I just got to $ element-> I want to echo one before the internal text .

How can I be the first one alone?

The above codes are all elements of Echo.

  • Is there any way to stop the search of Sareem, when children get the first of the original? I mean that we do not need to get all the elements, we need first, so it is wasting time to choose all the elements and give them the first one. Have to choose!

    It is better to stop simple.com to find a new item when the fist is found.

    Use break () after first running.

      foreach ($ html-> search ('span [class = st]') as $ element) {echo $ element-> Innertext; break; }  

    You can read more about break in this documentation from PHP.net:


    but I want to use this method instead of getting the first element of the array instead:

      acro $ html-> Search ('span [class = st]') - & gt; Innertext;  

    Loop is not required.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -