Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

PHP preg_grep()

<?php
   $foods = array("pasta", "steak", "fish", "potatoes");
   
   // find elements beginning with "p", followed by one or more letters.
   $p_foods = preg_grep("/p(\w+)/", $foods);
   
   print "Found food is " . $p_foods[0];
   print "Found food is " . $p_foods[1];
?>

Function preg_split()

<?php
   $ip = "123.456.789.000"; // some IP address
   $iparr = split ("/\./", $ip); 
   
   print "$iparr[0] <br />";
   print "$iparr[1] <br />" ;
   print "$iparr[2] <br />"  ;
   print "$iparr[3] <br />"  ;
?>

PHP preg_replace()

<?php
   $copy_date = "Copyright 1999";
   $copy_date = preg_replace("([0-9]+)", "2000", $copy_date);
   
   print $copy_date;
?>

PHP preg_match_all()

<?php
   $userinfo = "Name: <b>John Poul</b> <br> Title: <b>PHP Guru</b>";
   preg_match_all ("/<b>(.*)<\/b>/U", $userinfo, $pat_array);
   
   print $pat_array[0][0]." <br> ".$pat_array[0][1]."\n";
?>

PHP preg_match()

<?php
   $line = "Vi is the greatest word processor ever created!";
   // perform a case-Insensitive search for the word "Vi"
   
   if (preg_match("/\bVi\b/i", $line, $match)) :
      print "Match found!";
      endif;
?>

Function eregi_replace()

<?php
   $copy_date = "Copyright 2000";
   $copy_date = eregi_replace("([a-z]+)", "&Copy;", $copy_date);
   
   print $copy_date;
?>

Function spliti()

<?php

   $ip = "123.456.789.000"; // some IP address
   $iparr = split ("\.", $ip); 
   
   print "$iparr[0] <br />";
   print "$iparr[1] <br />" ;
   print "$iparr[2] <br />"  ;
   print "$iparr[3] <br />"  ;

?>

PHP Function eregi()

<?php
   $password = "abc";
   
   if (! eregi ("[[:alnum:]]{8,10}", $password))
   {
      print "Invalid password! Passwords must be from 8 - 10 chars";
   }
   else
   {
      print "Valid password";
   }
?>

Function ereg_replace()

<?php
   $copy_date = "Copyright 1999";
   $copy_date = ereg_replace("([0-9]+)", "2000", $copy_date);
   
   print $copy_date;
?>

Function ereg

<?php
   $email_id = "[email protected]";
   $retval = ereg("(\.)(com$)", $email_id);
   
   if( $retval == true )
   {
      echo "Found a .com<br>";
   }
   else
   {
      echo "Could not found a .com<br>";
   }
	
   $retval = ereg(("(\.)(com$)"), $email_id, $regs);
   
   if( $retval == true )
   {
      echo "Found a .com and reg = ". $regs[0];
   }
   else
   {
      echo "Could not found a .com";
   }
	
?>

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.