PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$string = "Sugar and spice and everything nice";
if (TheFunctionI'mlookingfor($string, "spice") {
//true it does contain spice
} else {
//no it really doesn't
}
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
// We can search for the character, ignoring anything before the offset
$newstring = 'abcdef abcdef';
$pos = strpos($newstring, 'a', 1); // $pos = 7, not 0
?>
if (strpos($_GET['name'], '/') === false) {
?>
<script language="JavaScript" type="text/javascript">
alert("Unable to create. Invalid characters "/" were found in the name specified.");
</script>
<?
} else {
//do what it's suppose to do if the char "/" is not in the $_GET['name']
}
and you see for some reason it doesn't work when I place a "/" in the $_GET['name'] var.
Basically I need a way of checking for invalid characters and if any then use the alert() javascript function. And if it isn't any then do what it's suppose to do.
I'm getting a little confused on this one, I don't know why.
$fix = array("<",">","{","}","[","]",'\"','/'); // a array set up with all of the invalid characters
$name = str_replace($fix,'',$_GET[name]);
if ($_GET['name'] != $name) {
?>
<script language="JavaScript" type="text/javascript">
alert("Unable to create. Invalid characters <,>,[,],{,},),(,/ were found in the name specified.");
</script>
<?
} else {
It works perfect. If anyone has any other ideas I'm open to suggestion.
Just thought I'd resolve this post for anyone else who has this problem could consider this post as an reasonable method.