Regular Expression

Bookmark and Share
Regex? What it is?
Regular Expression (Regex) is a concept of pattern matching (pattern matching) in a string. In general, the regular expression used for validation (in an information systems development), or used for text processing (text processing). However, sometimes a regular expression is also often used in Information Retrieval.
preg_match is a function regex in PHP, the syntax is as follows:
int preg_match (string $ pattern, string $ subject [, array & $ matches]);
$ pattern, is the string pattern to search
$ subject, is the text to be processed
$ matches, the search results, $ matches [0] will produce search results with the full pattern, while $ matches [1] will produce a text which sought in part from its parent.

. (dot) means any character except \ n
* Means that the character 0 or more
() Point to penggrup's or retrieve text
So the (.*) means taking the text with any character and any number

Below are examples of his own homemade code for checking a function:

<html>
<head>
<title>PHP Chalenge JokoArisPramono</title>
</head>
<body>
<h1>Pemeriksaan Struktur Syntax pada PHP</h1>
<table>
<form method="get">

<tr bgcolor="#CCCCCC">
<td height="50" align="left" valign="top" >Fungsi</td>
<td valign="top" width='50'>:</td>
<td><textarea name="txtFungsi" type="text" rows="5" cols='84'>
<?php
if(isset($_GET['txtFungsi'])) {
echo $_GET['txtFungsi'];
}
?>
</textarea></td>
</tr>

<tr>
<td></td>
<td></td>
<td>Format fungsi yang memenuhi syarat:</td>
</tr>

<tr>
<td></td>
<td></td>
<td>

<?php
preg_match_all("/^[_a-zA-Z][_a-zA-Z0-9]*\(\)[;]|^[_a-zA-Z][_a-zA-Z0-9]*\([&]?[$][a-z][_a-zA-Z0-9 ,&$]*\)[;]/m", $_GET['txtFungsi'], $jumlahFungsi);
for($i=0; $i <= count($jumlahFungsi); $i++) {
foreach($jumlahFungsi[$i] as $output) {

echo "<ul>";
echo "<li>" .$output. "</li>";
echo "</ul>";
}
}
?>

</td>
</tr>

<tr bgcolor="#CCCCCC">
<td></td>
<td></td>
<td><input type="submit" name="Submit" value="Submit"/></td>
</tr>
</form>
</table>
</body>
</html>
 

{ 0 komentar... Views All / Send Comment! }

Poskan Komentar