In addition to regular expressions, php intercepts specified strings.

Source: Internet
Author: User
$ Strsystem (& #039; pingwww.baidu.com & #039;); {code...} I want to intercept the ip address (ip address in []) in it ). There are several ways to ask. I only want regular expressions. However, regular expressions are not yet learned. If you want to write a small function, this problem will not solve $ str = system ('Ping www.baidu.com ');

Pinging www.a.shifen.com [115.239.210.27] with 32 bytes of data: reply from 115.239.210.27: byte = 32 time = 25 ms TTL = 54 reply from 115.239.210.27: byte = 32 time = 25 ms TTL = 54 replies from 115.239.210.27: byte = 32 time = 26 ms TTL = 54 replies from 115.239.210.27: byte = 32 time = 26 ms TTL = 54 115.239.210.27 Ping statistics: Packet: Sent = 4, received = 4, lost = 0 (0% lost ), estimated round-trip time (in milliseconds): Minimum = 25 ms, maximum = 26 ms, average = 25 ms Array

I want to intercept the ip address (ip address in []) in it ). There are several ways to ask.
I only want regular expressions. However, regular expressions are not yet learned.
If you want to write a small function, this problem will not be solved.

Reply content:

$ Str = system ('Ping www.baidu.com ');

Pinging www.a.shifen.com [115.239.210.27] with 32 bytes of data: reply from 115.239.210.27: byte = 32 time = 25 ms TTL = 54 reply from 115.239.210.27: byte = 32 time = 25 ms TTL = 54 replies from 115.239.210.27: byte = 32 time = 26 ms TTL = 54 replies from 115.239.210.27: byte = 32 time = 26 ms TTL = 54 115.239.210.27 Ping statistics: Packet: Sent = 4, received = 4, lost = 0 (0% lost ), estimated round-trip time (in milliseconds): Minimum = 25 ms, maximum = 26 ms, average = 25 ms Array

I want to intercept the ip address (ip address in []) in it ). There are several ways to ask.
I only want regular expressions. However, regular expressions are not yet learned.
If you want to write a small function, this problem will not be solved.

Preg_match ("/\ [(\ d + \. \ d + \. \ d + \. \ d +) \]/"," pinging www.a.shifen.com [115.239.210.27] with 32 bytes of data: From 115.239. ", $ matches );
Print_r ($ matches );

Mixed strpos (string $ haystack, mixed $ needle [, int $ offset = 0])
Find the location where ']' appears for the first time
Then use
String substr (string $ string, int $ start [, int $ length])
Truncate string


  

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.