PHP Lesson 8 Common Functions for String Splitting_PHP Tutorial

WBOY
Release: 2016-07-13 10:19:49
Original
924 people have browsed it

PHP Lesson 8 Common Functions for String Splitting

Course Overview:


Through this lesson, you can perform basic operations on strings.

String knowledge points:
1. Introduction to string processing
2. Commonly used string output functions
3. Commonly used string formatting functions
4. String comparison function
5. Application of regular expressions in strings
6. Regular expression used with per1


1.pathinfo();//Return the path information of the domain name

2.parse_url();
3.parse_str(); // Used to split parameters


pathinfo();
	<?php
	$str="http://blog.csdn.net/junzaivip";
	$arr = pathinfo($str);


	echo "<pre class="code">";
	print_r($arr);
	echo "
Copy after login
"; ?>



//Split a domain name into an array
<?php
	$str="http://blog.csdn.net/junzaivip.php?id=10&name=20";
	$arr = parse_url($str);


	$query = $arr[&#39;query&#39;];




	$arr2 = explode("&",$query);


	foreach ($arr2 as $val) {


		$arr3 = explode("=", $val);
		foreach ($arr3 as $value) {
			$arr4[$arr3[0]] = $arr3[1]; 
		}
		
	}


	echo "<pre class="code">";
	print_r($arr4);
	echo "
Copy after login
"; ?>

//Same method to get
<?php
	$str="http://blog.csdn.net/junzaivip.php?id=10&name=20";
	$arr= parse_url($str);
	parse_str($arr[&#39;query&#39;],$arr4);


	echo "<pre class="code">";
	print_r($arr4);
	echo "
Copy after login
"; ?>



//Method 3
<?php
	$str="http://blog.csdn.net/junzaivip.php?id=10&name=20";
	$arr= parse_url($str);
	
	$arr2 = preg_split(&#39;/&|=/&#39;, $arr[&#39;query&#39;]);


	//echo count($arr2);


	for ($i=0; $i < count($arr2); $i++) { 
		$arr3[$arr2[$i]] = $arr2[++$i];
	}


	echo "<pre class="code">";
	print_r($arr3);
	echo "
Copy after login
"; ?>





String knowledge points:
1. Introduction to string processing
2. Commonly used string output functions
3. Commonly used string formatting functions
4. String comparison function
5. Application of regular expressions in strings
6. Regular expression used with per1




String function
echo
print
printf(); direct output
sprintf(); returns directly


String concatenation character:
. Connect with dots
print "aaaaaaaaaa";
printf("----%s--$s--",$a,$b);
%s string
%d number
%f floating point type (%.2f represents two digits after the decimal point)


sprintf(); does not output directly, returns a new variable




Commonly used string formatting functions:
1. Take out spaces and string padding function
1.ltrim(); //Remove left space
2.rtrim(); //Remove right space
3.trim(); //Remove spaces on both sides
4.str_pad();//Used to fill spaces or customize characters to a specified length
5.str_repeat();//Used to repeat the previous characters (used to make unlimited category menus)
6.strlen() //Get the string length


echo "|". str_repeat("-",5)."bb";




String case conversion function
1.strtoupper();//Convert all to uppercase
2.strtolower();//Convert all to lowercase
3.ucfirst();//Capitalize the first letter
4.ucwords(); //The first letter of each letter is capitalized




Other string formatting functions:
1.strlen();//String length
2.strrev();//String flip
3.number_format();//Number character function in format
4.md5 //md5 encrypted string, 32-bit string
5.str_shuffle(); randomly shuffles the string, the number of digits remains unchanged



String functions:
String functions associated with html:
1.nl2br(): Convert /n to br tag
2.htmlspecialchars(); Convert to entity
' " &Convert to entity
":represents entity
<:less than sign
>:Greater than sign
3.addslashes() //' "" is added in front to reduce damage to the database
4.stripslashes() //' Remove the previous ones
3.strip_tags(); Only keep certain tags and remove the tags you want to remove


Note: It is recommended to carry out three controls before inserting into the database
1.[b][/b] Only convert limited tags and do tag filtering
2.addslashes();
' "" is added in front to reduce damage to the database
3.htmlspecialchars()
' " &Convert to entities to prevent any errors in the database



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/871182.htmlTechArticlePHP Lesson 8 Common Functions for String Splitting Course Summary: Through this lesson, you can perform basic operations on strings Operation. String knowledge points: 1. Introduction to string processing 2. Commonly used string output...
Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!