PHP Lesson 8 Common Functions for String Splitting_PHP Tutorial
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 ""; ?>
//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['query']; $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 ""; ?>
//Same method to get
<?php $str="http://blog.csdn.net/junzaivip.php?id=10&name=20"; $arr= parse_url($str); parse_str($arr['query'],$arr4); echo "<pre class="code">"; print_r($arr4); echo ""; ?>
//Method 3
<?php $str="http://blog.csdn.net/junzaivip.php?id=10&name=20"; $arr= parse_url($str); $arr2 = preg_split('/&|=/', $arr['query']); //echo count($arr2); for ($i=0; $i < count($arr2); $i++) { $arr3[$arr2[$i]] = $arr2[++$i]; } echo "<pre class="code">"; print_r($arr3); echo ""; ?>
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
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

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment