vesper
-
Posts
13 -
Joined
-
Last visited
Never
Posts posted by vesper
-
-
That would depend on how you implement your boolean logic. The most common way (IMO) of ensuring something only contains standard letters and numbers would be.
if(preg_match("#^[a-z0-9]+$#i", $input)) { echo "Valid"; }
You appear to be doing the opposite...
if(preg_match("#[^a-zA-Z0-9]#", $input)) { echo "Not Valid"; }
...which should still work.
Hi cags, I've just tried your example and it gives an error if you only use letter and numbers (which is the opposite to what I want). Should there be a ! before preg_match?
-
"[^a-zA-Z0-9]+$/s"
Since $ matches against the end, your code would have only returned an error if there were one or more characters that weren't a-zA-Z0-9 directly before the end of the input.
I see. So should removing +$ from the expression, eg. preg_match("/[^a-zA-Z0-9]/s", $variableName) now only allow a-z, A-Z and 0-9 as intended? Or should I continue testing it?
-
That's right. If it matches anything that isn't a-z, A-Z or 0-9 it gives an error. I've just removed the +$ and that seems to have cured it. Need to test it further though.
-
Hi,
I'm after what I'm hoping is a quick bit of help. I have the following in my code:
preg_match("/[^a-zA-Z0-9]+$/s", $variableName)
I got this code from an example which I was lead to believe only allows letters and numbers. However, it is also allowing underscores. Why is it doing this?
Thanks,
V.
-
Not with php I'm afraid. PHP executes on the server.
Hmm, bugger, that's what I figured. Thank you for replying!
-
Hi there,
Does anyone know if it is possible to get the url of all open tabs or windows? If so, any ideas how?
As always, your help would be much appreciated!
Vesper
-
It worked! Superb! Thanks for that! Hugely appreciated - headache seeping away now!
-
Hi metrostars,
I just tried it, unfortunately it didn't work. Thanks for the reply though.
-
Hi there,
I've got a piece of code that let's me obtain the title of a page using a given URL. However, if the title tag has any other code in it, for example <title id="something">, it does not work because the preg_match is looking for just the open and closing tags.
My question is: how can I get the code to ignore anything between '<title' and '>'??
The preg_match currently looks like this: preg_match("/<title>(.+)<\/title>/i",$file,$m)
Thanks.
-
hi jitesh, it works now! i would have thought that adding session_start(); to every page would start a new session!?!?
thanks for your help!!
-
Have every pages where are you are using session contains "session_start();" ?
If not then mention "session_start()" at first line of every pages.
hi, thanks for replying. no they don't. only the first page (index.php) contains "session_start()". i'll give it a try.
-
hi, i am wondering if someone out there may be able to help? i have <?php session_start(); ?> as the very first line on the first page of my site.
when i authenticate the user logon, i assign data read from the database to the session variables:
$_SESSION['sessionVariable1'] = $row['dbData1'];
$_SESSION['sessionVariable2'] = $row['dbData2'];
$_SESSION['sessionVariable3'] = $row['dbData3'];
$_SESSION['sessionVariable4'] = $row['dbData4'];
the variable names above are just made up, not those in the actual code, but you get the idea.
if i display the session variables using echo $_SESSION['sessionuserVariable1']; in the same page that I create them in there is no problem. however, once authentication has taken place the user is redirected using 'header'. the page the user is redirected to can not display the session variables!
does anyone have any idea why it is doing this?
[SOLVED] preg match allowing underscore
in Regex Help
Posted
Sorry, cags, my fault. I was looking for it to return an error, so I should have been using the bottom example, not the top one. (I used the top one first, then tried it with a ! before preg_match.)