lengte van $_GET['char'] beperken
ik zou de lengte van een var, die via get wordt opgenomen, willen beperken tot één letter/cijfer.
Hoe zorg ik er dus voor dat lenger niet werkt ?
Dit is wat ik heb:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
elseif (isset($_GET['char'])){ // artists first char set ?
if (ctype_alpha($_GET['char']{0})){ // letter ?
$sql = mysql_query("SELECT * FROM artist WHERE LOWER(LEFT(name, 1)) = '" . $_GET['char']{0} . "'");
if(!$sql){ echo "error on the char part: ".mysql_error();}
echo "<ul>\n";
while ($row = mysql_fetch_array($sql)){
echo "<li><a href=\"".$_SERVER['PHP_SELF']."\">".$row['name']."</a></li>\n";
}
echo "</ul>\n";
}
elseif (ctype_digit($_GET['char'])){ // number ?
$sql = mysql_query("SELECT * FROM artist WHERE name RLIKE '^[0-9]'");
if(!$sql){ echo "error on the char part: ".mysql_error();}
echo "<ul>";
while ($row = mysql_fetch_array($sql)){
echo "<li><a href=\"".$_SERVER['PHP_SELF']."\">".$row['name']."</a></li>\n";
}
echo "</ul>";
}
else{ // wrong ?
echo "Invalid char";
}
} // end if first char
if (ctype_alpha($_GET['char']{0})){ // letter ?
$sql = mysql_query("SELECT * FROM artist WHERE LOWER(LEFT(name, 1)) = '" . $_GET['char']{0} . "'");
if(!$sql){ echo "error on the char part: ".mysql_error();}
echo "<ul>\n";
while ($row = mysql_fetch_array($sql)){
echo "<li><a href=\"".$_SERVER['PHP_SELF']."\">".$row['name']."</a></li>\n";
}
echo "</ul>\n";
}
elseif (ctype_digit($_GET['char'])){ // number ?
$sql = mysql_query("SELECT * FROM artist WHERE name RLIKE '^[0-9]'");
if(!$sql){ echo "error on the char part: ".mysql_error();}
echo "<ul>";
while ($row = mysql_fetch_array($sql)){
echo "<li><a href=\"".$_SERVER['PHP_SELF']."\">".$row['name']."</a></li>\n";
}
echo "</ul>";
}
else{ // wrong ?
echo "Invalid char";
}
} // end if first char
Gewijzigd op 01/01/1970 01:00:00 door Altin
Code (php)
1
2
3
4
5
6
2
3
4
5
6
<?php
if(preg_match('/[0-9a-z]{1}/i', $_GET['char']))
{
// $_GET['char'] bestaat uit 1 letter of cijfer
}
?>
if(preg_match('/[0-9a-z]{1}/i', $_GET['char']))
{
// $_GET['char'] bestaat uit 1 letter of cijfer
}
?>
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
<? if (isset($_GET['band'])){ // artist set ?
if (preg_match('/[0-9a-z]{1}/i', $_GET['char'])){
if (ctype_alpha($_GET['band'])){
$sql = mysql_query("SELECT * FROM artist WHERE name=".$_GET['band']."");
while ($row = mysql_fetch_array($sql)){
echo "".$row['name']."";
}
}
else{
echo "Invalid band";
}
}
else { echo "niet maar 1 char";}
} // end if artist ?>
if (preg_match('/[0-9a-z]{1}/i', $_GET['char'])){
if (ctype_alpha($_GET['band'])){
$sql = mysql_query("SELECT * FROM artist WHERE name=".$_GET['band']."");
while ($row = mysql_fetch_array($sql)){
echo "".$row['name']."";
}
}
else{
echo "Invalid band";
}
}
else { echo "niet maar 1 char";}
} // end if artist ?>
{
echo 'mag niet';
}
Thanks, dat werkte :)
Blanche schreef op 24.02.2007 17:57:
Ooo, ja natuurlijk '-_- Sorry
Ik wil dat $char, de warde heeft van het eerste teken, ook als het langer is dan 1 ...
Thanks!