php basics tutorial php built in function example tutorial

  • 2020-05-19 04:27:04
  • OfStack

So now we will explain the built-in function of php
There are case conversion related functions
Text html label handler

Case dependent function
 
strtolower() 
strtoupper() 
ucfirst() 
ucword() 


HTML tag - related string formatting function
 
nl2br() 
htmllentities() 
htmlspecialchars() 
stripslashes() 
strip_tags() 
number_format() 
strrev() 
md5() 


All string handling functions in php do not modify the original string, but instead return a newly formatted string
 
<?php 
// Convert to lowercase  
$a='www.ofstack.com'; 
echo strtolower($a); 
// The results of :www.ofstack.com 

// Convert to uppercase  
$a='www.ofstack.com'; 
echo strtoupper($a); 
// The results of :WWW.ofstack.com 

// Capital letter  
$a='www.ofstack.com'; 
echo ucfirst($a); 
// The results of :Www.ofstack.com 

// Each word begins with a capital letter  
$a='i love you'; 
echo ucword($a); 
// The results of :I Love You 

/* 
 Tip: everyone knows case, so does it make a difference between lowercase and uppercase, but why  
 in win Under the system php Loose case   But in the linux No pulling under the system   Do not scribble case  
 Such as  
 When the class is automatically loaded  
<?php 
function _autoload($className){ 
include strtolower($className).'.class.php'; 
} 
$obj= new MyClass; 
 So that loads myclass.class.php 
 Because the file name is always lowercase you have to convert lowercase  
?> 
*/ 

//nl2br Converts a space into an entity <br/> because 1 Generally, the newline is displayed in the browser <br/>  For example, in the form message book must be converted or the line will not fold successfully   No amount of white space is enough 1 A blank space  
$a=' 
i 
love 
you 
'; 
echo $a; 
echo nl2br($a); 
 The results of 1:i love you 
 The results of 2: 
i 
love 
you 

// Form submission if you don't do it html The label processing then will display the style directly or js The code runs directly  
/* 
<form> 
<input type='text' name='title'> 
<input type='submit' name='submit' value=' submit '> 
</form> 

 When you enter  
<H1>www.ofstack.com<H1> 
1 The submission will appear 1 The large font  
 But you wanted it  
<H1>www.ofstack.com<H1> The results of  
 So let's deal with that  
 When the input <script>alert('www.ofstack.com')</script> 
1 The commit will run javascript 
 This is bad   Must be dealt with to prevent hackers from finding your entry  
 The form is submitted by default get 
*/ 
// When you enter <div><h1>www.ofstack.com</h1></div> 
echo htmlspecialchars($_GET['title']);// The filter  
 The results of :<div><h1>www.ofstack.com</h1></div> 
 See the source code for the rest <  and  > It's been replaced by < > It will be displayed on the page prototype  
 There are 1 Point to the main   If you don't deal with <div > Some duplicate articles have tag styles that can mess up your page layout   may css conflict  
htmllentities() Function user and htmlspecialchars() On the contrary, don't say  

 You can use that tag when you need it strip_tags() function  
echo strip_tags($_GET['title'],'<b><p><strong><h1>'); 
 The result of submitting is that you view the source code   You will find <div> Without the  

/* 
 Join the input i love 'jb51'; 
 The submission result is  i love \'jb51\' The backslash escaped  
 So what if I want to output the original  
 You can use this php function stripslashes() 
 Cancel the escape  
echo stripslashes($_GET['title']); 
 As a result, i love 'jb51'; 
 If they contain html Labels like this  
<a href="//www.ofstack.com/">i love 'jb51'</a> 
 What if I want the prototype output   You can use 2 So let's combine these two functions   I already said that  
echo htmlspecialchars(stripslashes($_GET['title'])); 
 Results: <a href="//www.ofstack.com/">i love 'jb51'</a> 
*/ 

//number_format() This function is the formatted currency function   Different countries have different habits 1 Then the required currency display is not 1 Such as mall China money is usually in this format  
 The thousandths are separated by commas   Reserve a few bits for use   Person 'decimal point' ' 
 The usage of this function is simple  
number_format($money, Keep a few decimal places ,' What separates the decimal points ',' What separates the thousandths ') 
$price='123465789.233'; 
echo number_format($money,2,',','.'); 
 Results: 123.465.789 . 23 
echo number_format($money,2,'.',',');// The Chinese  
 Results: 123,465,789.23 

//strrev() Make the string come back  
$str='//www.ofstack.com'; 
echo strrev($str); 
 The results of :moc.tenwii.www//:ptth 

//md5 Is encrypted   Usernames and passwords must be encrypted to prevent hackers  
$a='admin'; 
echo $b= md5($a); 

Related articles: