PHP: Built-In Functions

PHP: Built-In Functions

Example: strtoupper function


	<?php
	   $name="William Smith";
	   echo "<p>My name is $name.</p>";
	   echo "<p>My name is " . strtoupper($name) . ".</p>";
	?>
	

Run it now

Example: number_format function


	<?php
	  $salary = 35000;
	  $name = "Paul Smith";
	  echo "<p>$name's salary is $salary</p>";
	  echo "<p>$name's salary is $" . number_format($salary,  2, '.', ',') . "</p>";
	?>
	

Run it now

Example: strlen and substr_count functions


	<?php
		
		$name = "John Michael Smith";
		
		$count1 = strlen($name);
		$num_spaces1 = substr_count($name," ");
		$count2 = $count1 - $num_spaces1;
		
		echo "<p>$name</p>";
		echo "<p>John, your full name has $count1 characters in it when you include spaces.</p>";
		echo "<p>John, your full name has $count2 characters in it when you do not include  
									spaces.</p>";
		
		$name = str_replace("Michael","Robert",$name);
		
		echo "<p>Your full name is now $name.</p>";

	?>
	

Run it now

Example: date function


	<?php
		$date1 = date("m/d/y"); 
		echo "<p>The date today is $date1.</p>";
		echo "<p>Tomorrow is " . date('l', time()+86400) . ".</p>";
	?>
	

Run it now

Example: Simple PHP Output with Hyperlink


	<?php
		$x=10.2; 
		echo "<p>". ceil($x)  ."</p>";
		echo "<p>". floor($x) ."</p>";
		echo "<p>". round($x) ."</p>";
		echo "<p>". pow($x,2) ."</p>";
		echo "<p>". sqrt($x) ."</p>";
		echo "<p>".  rand(1,100) ."</p>";
	?>
	

Run it now