Doug deloy: some Sample php code and apps
|
Using regular expressions to search for a phone no from a file Here's the code for the example$filename="$_SERVER[DOCUMENT_ROOT]/datebook"; foreach ($lines as $the_line) { $fields=explode(":",$the_line); $name=$fields[0]; $phone=$fields[1]; if( preg_match("/^$area_code-/","$phone")){ echo "$name: $phone "; $count++; } } if ($count == 0 ){ echo "The area code is not found. "; } |