Length of a String

The length property of a string is determined with the strlen( ) function, which returns the number of eight-bit characters in the subject string:
integer strlen(string subject)
We used strlen( ) earlier in the chapter to compare string lengths. Consider another simple example that prints the length of a 16-character string:
print strlen("This is a String");  // prints 16
Related Posts:
  • PHP operators are characters Artithmetic Operators OperatorDescription +Addition -Subtraction *Multiplication /Division %Modulus (remainder of a division) ++Increment --Decrement Assignment Operator Op… Read More
  • keep your session secure php Use SSL when authenticating users or performing sensitive operations. Regenerate the session id whenever the security level changes (such as logging in). You can even regenerate the session id every request if you wish. H… Read More
  • You want to extract part of a string, starting at a particular place in the string Use substr( ) to select your substrings: $substring = substr($string,$start,$length); $username = substr($_REQUEST['username'],0,8); … Read More
  • convert time in php <?php $thishour = time() + (4*60*60); $newTime = date("d m Y H:i:s",$thishour); echo $newTime; ?>); … Read More
  • SQL Injection Attacks This appeared to be an entirely custom application, and we had no prior knowledge of the application nor access to the source code: this was a "blind" attack. A bit of poking showed that this server ran Microsoft's IIS 6 alo… Read More
  • Opening a Remote File You want to open a file that's accessible to you via HTTP or FTP. Pass the file's URL to fopen( ):  $fh = fopen('http://www.example.com/robots.txt','r') or die($php_errormsg);     When fopen( ) is passed … Read More
  • Apache-Specific Functions These functions enable you to access Apache internal features—they form a high-level interface to some Apache API functions. Consequently, these functions are available only if you have compiled PHP as an Apache module. … Read More
  • Control Structures if else elseif/else if Alternative syntax for control structures while do-while for foreach break continue switch declare return require include require_ once include_ once goto … Read More
  • send images to mail box <?php $message = "<html><head></head><body>"; $message .= "<img src='http://exp.com/images/logo.jpg' alt='' /> </body> </html>"; $cleanedFrom="admin@abfdgd.com"; $headers = "Fr… Read More
  • XML file using the DOM API //Use PHP's DOM XML extension. Here's how to read XML from a file: $dom = domxml_open_file('books.xml'); //Here's how to read XML from a variable: $dom = domxml_open_mem($books); //You can also get just a single node. H… Read More
  • SQL Injection Prevention the value should only be a positive integer value, since it's an id number. We do sometimes use other variables that could be a letter, or a string of text, for example, the search results pages. $variable = "0"; if (is… Read More
  • Checking if a Host Is Alive Use PEAR's Net_Ping package: require 'Net/Ping.php'; $ping = new Net_Ping; if ($ping->checkhost('www.oreilly.com')) { print 'Reachable'; } else { print 'Unreachable'; } $data = $ping->ping('www.oreilly.com… Read More
  • PHP Redirect - Redirect Script? PHP Redirect Function header('Location: destination.php'); exit();   ou need the Location: part so the browser knows what header it's  receiving. Also, don't forget to  do an exit() or die() right after… Read More
  • Changing File Permissions by php Use chmod( ) to change the permissions of a file:  chmod('/home/user/secrets.txt',0400);   Use chown( ) to change a file's owner and chgrp( ) to change a file's group: <?php chown('/tmp/myfile.txt','skla… Read More
  • Php get_meta_tags-Extracts all meta tag content attributes get_meta_tags — Extracts all meta tag content attributes from a file and returns an array <?php// Assuming the above tags are at www.example.com$tags = get_meta_tags('htt… Read More