Jump to content

Recommended Posts

Well I'm kind of lost on this one.

I've been looking all over to try and find a way to remove all cracters accept numbers from a verable.

 

And I'm kind of new, when it comes to removing certain caracters from the verable.

 

an eg would be

 

$id = 00289 // Good verable

$id = ".Some hacking going on." // Bad Verable

 

So since I only need numbers to past though the verable, any idea of the best way to solve this?

If you only want to check if it's a number, use is_numeric

<?php
$var = 1;
if (is_numeric($var)) echo 'is number';
else echo 'is not a number';

$var = 'hello world';
if (is_numeric($var)) echo 'is number';
else echo 'is not a number';
?>

 

If you only want to accept a number use intval that converts strings into numbers:

<?php
$var = 'hello';
$var = intval($var); //becomes 0

$var = '23';
$var = intval($var); //becomes 23
?>

Well this is my code and still not working.

 

<?php
include("../header.php");
$id = $_GET['id'];
if (is_numeric($id)) {
echo "<p align=\"center\">\n";
echo "<img src=\"http://www.stateofmind.me.uk/images/cineworld/starwars/DSC".$id.".jpg\" alt=\"DSC".$id."\" border=\"0\" />\n";
echo "<br />\n";
echo $id;
echo "<br /><br />\n";
echo "<a href=\"/cineworld/startwars.php\">Back</a>\n";
echo "</p>";
} else {
echo "That is not a numeric value\n";
}
include("../footer.php");
?>

 

with number string and caracters it still outpost as that is not a numeric value.

The only error message are from the include function which is because for that pertiacal header and footer, are not on the site, I'm just testing the main code it self.

 

Which gives these message:

 

$id = 00127 // output is: That is not a numeric value

$id = test // output is: That is not a numeric value

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.