Jump to content

preg_match help


tobeyt23

Recommended Posts

With the below I would like to get them to return true if grades 9-12, 6-8 or 1-5 respectfully. This doesn't seem to work!

 

<?php
preg_match('/[{9}{10}{11}{12}]/',$book['grade_level'])
preg_match('/[{6}{7}{8}]/',$book['grade_level'])
preg_match('/[{1}{2}{3}{4}{5}]/',$book['grade_level'])
?>

Link to comment
https://forums.phpfreaks.com/topic/143970-preg_match-help/
Share on other sites

Does $grade_level contain just a number eg, 10 If so you can do

 

if($grade_level >= 9 && $grade_level <= 12)
{
    // grade level is 9 to 12
}
elseif($grade_level >= 6 && $grade_level <= 
{
    // grade level is 6 to 8
}
elseif($grade_level >= 1 && $grade_level <= 5)
{
    // grade level is 1 to 5
}
else
{
    // grade level is unknown.
}

Link to comment
https://forums.phpfreaks.com/topic/143970-preg_match-help/#findComment-755440
Share on other sites

@wildteen: No, you can't do if (something >= 1 && <= 2).  You need to list the variable twice.

<?php
$grade_level = 10;
if ($grade_level >= 9 && $grade_level <= 12) {
....

Oops! Yea sorry about that. Shouldn't be typing and watching TV at the same time. I'll correct my post.

Link to comment
https://forums.phpfreaks.com/topic/143970-preg_match-help/#findComment-755443
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.