Dynadot — .com Transfer

Count number of characters

Spaceship Spaceship
Watch

jroy

VIP Member
Impact
13
Ok, I'm importing a text file into a php file using $textfile = file("FilePath"), is there any easy way to count the number of characters in a certain line? Like if I wanted to have a loop go through each line and count how many characters it is and then do a certain action?

Thanks,
Josh
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
strlen function can do this.

PHP:
<?php
$string = "Hi it is me Nick";
$length = strlen($string);
echo "The string: $string <br>Is $length characters long";
?>
 
0
•••
Thanks, I knew there was a function to do this, but couldn't remember what it was.
 
0
•••
Ok, I created my script to open the file and count the number of characters in the string, but the value it inserts into a database for each line is always 2 more then the actual value except for the last line it seems.
 
0
•••
That is because of the CrLf (\r\n) at the end of the string

PHP:
<?php 
$string = trim($string);
$length = strlen($string); 
echo "The string: $string <br>Is $length characters long"; 
?>
 
0
•••
Thanks.
 
0
•••
use addslashes also...
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer

We're social

Domain Recover
DomainEasy — Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back