PHP's manipulation of strings and understanding of PHP regular expressions

PHP's most text processing is very powerful.

1. The difference between ' and " 

<? php
 // Special characters in double quotes will be parsed 
echo "Hello\t I'm good"; echo "<hr>" ;
 // Double quotes parse the variable 
$name = 'chenglin' ​​;
 echo "Hello, $ name " ;echo "<hr>";
 
echo 'Hello\ tHello'; echo "<hr>" ;
 $name = 'chenglin' ​​;
 echo "Hello, $name " ;
 ?>

2, escape character \ 

  The escape character has two functions, one is to give the character a special meaning (\t is a tab character), and the other is to format the special character (\'makes' a non-delimiter)

<? php
 // Escape ', otherwise an error will be reported 
echo 'I \'am a tea\cher'; echo "<hr>" ;
 // Escape t, \t is now a tab 
echo "Hello\t me OK"; echo "<hr>" ;
 ?>

3. Add, delete, modify and check the string (the string can be called an array)

  check:

 

<?php
$domain = 'http://www.baidu.com';

//查询
echo $domain[3];echo '<hr>';  
echo $domain{3};echo '<hr>';  

// Intercept the entire string starting from subscript 7 
echo  substr ( $domain ,7); echo '<hr>' ; 
 // Intercept 3 characters starting from subscript 7 
echo  substr ( $domain ,7,3); echo '<hr>' ; 
 ?>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325987204&siteId=291194637