php - create a find function to get string between characters -


(first question posted stack)

i'm trying create function that:

  1. searches string variable value
  2. when variable value found, remove before variable value
  3. and remove after following pre-determined string

here code:

<?php       $user_id = '5';     $week_start = "2014-8-01 00:00:00";                                  $week_end = "2014-09-01 23:59:59";       //get row information     $result_show_picks = mysql_query("         select          id, uid, pick, date_submitted         picks_recorded         uid = '" . $user_id . "'         , date_submitted > '" . $week_start . "'         , date_submitted < '" . $week_end . "'         limit 1         ", $connection);          if (!$result_show_picks) {             die("database query failed: " . mysql_error());     }           while ($row_picks = mysql_fetch_array($result_show_picks)) {             echo "id = " . $row_picks[id] . "<br />";             echo "uid = " . $row_picks[uid] . "<br />";             echo "pick = " . $row_picks[pick] . "<br />";             echo "date_submitted = " . $row_picks[date_submitted] . "<br />";              /* output                  id = 233                 uid = 5                 pick = |1046:648|145:66|1348:736|506:334|97:37|710:434|1421:768|361:257|325:235|698:430|1457:796|1142:694                 date_submitted = 2014-08-18 02:50:00             */              $pick_input = $row_picks[pick];         };          function assign_values($pick_input) {             $str1 = ":";             $str2 = "|";             $team_picked = substr($pick_input,$str1,$str2);             return                  $var1 = value1,                 $var2 = value2,                 $var3 = value3,                 etc, etc;                  /* hoped return (but have no idea if feasible):                     $pick_1046 = "648",                     $pick_145 = "66",                     $pick_1348 = "736",                     etc, etc;                 */         };     ?> 

this how want use it:

    <?php          if($row['this_games_id'] == $pick_1046){             echo "yes";         };     ?> 

i hope makes sense. in case matters, football picks site friends , not have gambling of sort involved.

thank help.

preform below on each of strings want information , whatever between %start% , %end%.

$start = '%start%'; $end   = '%end%';  $long_string = 'lorem ipsum dolor sit amet, consectetur adipisicing elit.%start%i want text%end% tempore quae explicabo tempora eum aspernatur harum, rem itaque cumque ipsum neque!';  $pos1 = (stripos($long_string, $start) + strlen($start)); $pos2 = (stripos($long_string, $end));  $result = substr($long_string, $pos1, ($pos2 - strlen($long_string)));  echo $result; 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -