Search for strings in Js and php

Source: Internet
Author: User

I have been learning javascript recently and have never updated my blog. I have been watching javascript video tutorials. Li Yanhui spoke about it very well. I have never read or written any code in the JavaScript video tutorial. I am going to write the code today. It took me half a day to get it out. Alas, it seems that I still need to manually write more to learn this stuff. Exercise: extract and output all words with a door from the following words. Early morning dust invasion morning privilege Chen diligent and angry atmosphere distinguish sentiment Fen lead powder light powder Autumn full roots qi root wall root diligence valve tip ball door right door missing pouring confirmation relatives and poor predecessors flag former strong lover man strong man seeking strength to get up his predecessor living qi qishen first uses JavaScript to implement output, the Code is as follows. // Js version search string var str = 'morning dust invasion morning privilege Chen diligent and angry atmosphere distinguish sentiment Fen lead powder light powder Autumn full roots gas root wall root diligence valve tips empty portal tilting basin confirm loved ones poor predecessors the former strong man of the Flag sought strength to get up and his predecessor lived in the old man and extended '; var strarr = new Array (); strarr = str. split (''); for (var I = 0; I <strarr. length; I ++) {if (strarr [I]. match ('door') {document. write (strarr [I] + '<br>') ;}} output result:
I took a look at php some time ago and wrote it using php .. The Code is as follows: <? Php // php search string $ str = 'morning dust invade the morning privilege Chen diligent and angry atmosphere distinguish sentiment points lead powder light powder Autumn full from the root gas root wall root diligence valve tips ball door right door missing pour basin confirm relatives and poor predecessors the former strong man of the Flag sought strength to get up and his predecessor lived in the old man and extended '; $ str1 = explode ('', $ str); // print_r ($ str1); for ($ I = 0; $ I <count ($ str1 ); $ I ++) {if (strstr ($ str1 [$ I], 'Gateway') {echo $ str1 [$ I]. '<br>' ;}}?> Php result output:


 
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.