Home  >  Article  >  Backend Development  >  How to find a certain value in php and print it out?

How to find a certain value in php and print it out?

WBOY
WBOYOriginal
2016-09-21 14:13:14946browse

I have used preg_match to find a certain string. If there is xxx, I will display it as xxx
This is what I decided. As long as the string matches
But what I want to know now is
How to print a certain string?
Because the string will change, I want to print it out
I use PHP's HTTP USER AGENT to detect the device's data

Assume this paragraph

<code>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36</code>

I want to print out Mac OS X 10_10_5 and display it as Mac OS X 10.10.5

and

<pre class="brush:php;toolbar:false">&lt;code&gt;Mozilla/5.0 (Linux; Android 4.4.2; ASUS_T00G Build/KVT49L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36&lt;/code&gt;</pre>

I want to print out Android 4.4.2 and ASUS_T00G

and the last

<pre class="brush:php;toolbar:false">&lt;code&gt;Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53&lt;/code&gt;</pre>

In addition to printing out iPhone, I also want to print out OS 7_1_2 and display it as OS 7.1.2
How to detect this?
I will judge that if there is Intel Mac OS Those strings I described
How to judge this?


Reply content:

I have used preg_match to find a certain string. If there is xxx, I will display it as xxx. This is what I decided. As long as the string matches

But what I want to know now is

How to print a certain string?

Because the string will change, I want to print it out
I use PHP's HTTP USER AGENT to detect the device's data

Assume this paragraph

<code>Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36</code>

I want to print out Mac OS X 10_10_5

and display it as

Mac OS X 10.10.5

and <pre class="brush:php;toolbar:false">&lt;code&gt;Mozilla/5.0 (Linux; Android 4.4.2; ASUS_T00G Build/KVT49L) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36&lt;/code&gt;</pre> I want to print out

Android 4.4.2

and

ASUS_T00G

and the last <pre class="brush:php;toolbar:false">&lt;code&gt;Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53&lt;/code&gt;</pre> In addition to printing out iPhone, I also want to print out

OS 7_1_2

and display it as

OS 7.1.2

How to detect this? I will judge that if there is Intel Mac OS Those strings I described How to judge this?

Look at this:
https://my.oschina.net/junn/b...

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn