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
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
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
Share on other sites

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.