Jump to content

Recommended Posts

i want to modify my search thing using file_get_contents to match the profile age instead of suspension reason.

 

 

in order to change this i need to match this. line.

<b>Age:</b> 16

 

 

i am trying to do something like

 

case($line=="<b>Age:</b>")

 

then inside of that put an age variable but i get nothing.

 

for age i did

$age= ($age < 18) ? 'minor' : 'adult';

 

but nothing works when i pass age into the line string

 

ultimately i want to make it so that if the matched age is less than 18 to say minor else pass as an adult.

Link to comment
https://forums.phpfreaks.com/topic/257750-using-regex-to-match-age/
Share on other sites

This is probably what you want:

 

<?php

$string = '<b>Age:</b> 16';

if (preg_match('~<b>Age:</b> (\\d+)~', $string, $match)) {
    echo ((int)$match[1] < 18) ? 'minor' : 'adult';
}

?>

 

no.

If you are not sure of the age data and you need a tight regex you can use this.

 

$string = '<b>Age:</b> 16';

if (preg_match('~^<b>Age:</b> ([1-9][0-9]?|10[0-5])$~', $string, $match)) { //max age 105
    echo ((int)$match[1] < 18) ? 'minor' : 'adult';
}

 

else, if you are sure of the data, you can use this:

 

$string = '<b>Age:</b> 16';

if (preg_match('~^<b>Age:</b> (\d{1,3})$~', $string, $match)) {
    echo ((int)$match[1] < 18) ? 'minor' : 'adult';
}

 

or even:

 

$pattern = '^<b>Age:</b> (\d+)$';

 

curious, where are you getting the contents of $line?

yeah it is all messed up now.

 

<?php

$submit = isset($_POST['submit'])?$_POST['submit']:false;
  if ($submit) {
   $url = 'http://vampirefreaks.com/profile.php?user=';
      $user = $_POST['user'];
      $file = file($url.$user);//retrieves url and puts into plain text format
      foreach ($file as $lines) {
          $line=strip_tags($lines);
          $line=trim($line);
          if ($line != ''||!empty($line)) {  
          



//echo "$line<br>\n"; // debug code
              $line = str_replace('LOTCC.bcp();', ' ',$line);//strip out multiply.com javascript code
              $line = preg_replace('/\s+/', ' ', $line); //strip out white space
              $line = preg_replace('/\s+$/', ' ', $line);//strip out white space
              $redopen="<font color=red>";
              $greenopen="<font color=green>";
              $pinkopen="<font color=#f600ff>";
              $blueopen="<font color=blue>";
              $purpleopen="<font color=purple>";
              $close="</font>";
            
            switch($line){
case ($line =='THIS USER DOES NOT EXIST'||$line == 'Error Retreiving user info'):
$message ="$redopen this user is dead!$close";
break;
case (preg_match('~^<b>Age:</b> ([1-9][0-9]?|10[0-5])$~', $line, $match)):
$message= ((int)$match[1] < 18) ? ''.$redopen.'minor Posting in 18+ Classifieds'.$close.'' : $match[1];
break;
}}}}
  if($message){echo $message;}else{echo $form;}
  

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.