Home > Backend Development > PHP Tutorial > Use PHP to view your own people in the URL

Use PHP to view your own people in the URL

autoload
Release: 2023-04-09 20:30:01
Original
2001 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:

<?php 

$url = &#39;http://www.php.cn&#39;; 
$key = &#39;cn&#39;; 
if (substr_count($url, $key) == false) 

  echo &#39;URL中不存在子字符串&#39;.$key; 
 else 
  echo &#39;URL中存在子字符串&#39;.$key; 
  
echo "<br>";

$key1=&#39;com&#39;;
if (substr_count($url, $key1) == false)
 echo &#39;URL中不存在子字符串 &#39;.$key1.&#39; <br>&#39; ; 
 else 
  echo &#39;URL中存在 &#39;.$key1.&#39; <br>&#39; ;

?>
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:

<?php 

$url = &#39;http://www.php.cn&#39;;  

$key = &#39;cn&#39;; 
  
if (strpos($url, $key) == false) { 
  echo &#39;URL中不存在子字符串&#39;.$key.&#39; <br>&#39; ; 
} 
else { 
  echo &#39;URL中存在子字符串 &#39;.$key.&#39; <br>&#39; ; 
} 
  
echo "<br>";
$key1 = &#39;com&#39;; 
  
if (strpos($url, $key1) == false) { 
  echo &#39;URL中不存在子字符串 &#39;.$key1;
} 
else { 
  echo &#39;URL中存在子字符串 &#39;.$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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template