What to do if php string splitting fails

藏色散人
Release: 2023-03-17 20:38:02
Original
3279 people have browsed it

Solution to PHP string segmentation failure: 1. Open the corresponding PHP code file; 2. Use the "str_replace()" function to replace the tab key in the file; 3. Use "explode("_" ,$line);" method can be used to split the string.

What to do if php string splitting fails

The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer

What to do if php string segmentation fails ?

Solution to the problem that the explode() function cannot split the tab key in php

I encountered a problem a few days ago: it requires reading each character in the file One row, and split each column into an array, where each column is separated by the tab key ("\t").

It is natural to think of using fgets() to read each line in the file and split it using the explode() function.

$f=fopen("xxx","r");
$line=fgets($f);
$line=explode("\t",$line);
Copy after login

I found that the expected effect was not obtained. The explode() function cannot split a string with the tab key as the separator.

Later I thought of a way, use str_replace() function to replace the tab key in the file, and then use explode() to split it.

$f=fopen("xxx","r");
$line=fgets($f);
$line=str_replace("\t","_",$line);
$line=explode("_",$line);
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php string splitting fails. For more information, please follow other related articles on the PHP Chinese website!

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 [email protected]
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!