Converting to and from Strings

You want to convert to and from strings.

Use (string) cast or the strval() function.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="EN" lang="EN">
<head>
<title>PHP</title>
<meta Name="Author" Content="Hann So">
</head>
<body>
<p>
<?php
$num = 12.345;
echo(string) $num, "<br />";
echo strval($num), "<br />";
?>
</p>
</body>
</html>

View the effect


Strings | Introduction | Formatting Strings | Converting to and from Strings | Finding the Length of a String | Accessing Substrings | Extracting Substrings | Replacing Substrings | Taking Strings Apart | Processing a String One Byte at a Time | Reversing a String by Word or Byte | Controlling Case | Trimming Blanks from a String | Wrapping Text at A Certain Line Length
© 2008: Hann So
email: hso@voyager.deanza.edu