Use PHP to view your own people in the URL

autoload
Release: 2023-04-09 20:30:01
Original
1899 people have browsed it

Use PHP to view your own people in the URL

Method 1: Use the substr_count() function

a. Grammar format:

substr_count(string,substring,start,length)
Copy after login
  • string: The string being checked.

  • #substring: The string to search for.

  • #start: Specifies where to start searching in the string. (Optional)

  • #length: Specifies the length of the search. (Optional)

Return value: Returns the number of times the substring appears in the string.

b. Example:

"; $key1='com'; if (substr_count($url, $key1) == false) echo 'URL中不存在子字符串 '.$key1.' 
' ; else echo 'URL中存在 '.$key1.'
' ; ?>
Copy after login

c. Output:

URL中存在子字符串cn URL中不存在 com
Copy after login

Method 2: Use the strpos() function

a. Syntax format:

strpos(string,find,start)
Copy after login
  • string The string to be searched.

  • #find The string to be found.

  • #start Where to start the search. (Optional)

Return value: Find the first occurrence of a string in another string.

ps: The strpos() function is case-sensitive.

b.Example:

' ; } else { echo 'URL中存在子字符串 '.$key.' 
' ; } echo "
"; $key1 = 'com'; if (strpos($url, $key1) == false) { echo 'URL中不存在子字符串 '.$key1; } else { echo 'URL中存在子字符串 '.$key1 ; } ?>
Copy after login

c.Output:

URL中存在子字符串 cn URL中不存在子字符串 com
Copy after login

Recommendation:《php video tutorial》《php tutorial

The above is the detailed content of Use PHP to view your own people in the URL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
url
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!