1. Computing & Technology

Discuss in my forum

Is_string () PHP Function

Is this a string?

By , About.com Guide

See More About:
The Is_string () PHP function is used to check if a value is a string. This could be used within an if () statement to treat strings in one way and non-strings in another. It will return true or false.
 <?php 
 if (is_string(23)) 
 {
 echo "Yes";
 } else {
 echo "No";
 }
 ?>
 
The code above should output "No" because 23 is not a string. Let's try this again:
 <?php 
 if (is_string("Hello World")) 
 {
 echo "Yes";
 } else {
 echo "No";
 }
 ?>
 
Since "Hello World" is a string, this would echo "Yes".

©2012 About.com. All rights reserved.

A part of The New York Times Company.