Jump to content

papaface

Members
  • Posts

    1,437
  • Joined

  • Last visited

    Never

Posts posted by papaface

  1. Try

    <?php
    $numWanted = trim($_POST['num_wanted']);
    // create an array of numbers called $numArray
    $numArray = array(12, 0, 89, 64, 23, 50);
    ?>
    <?php
    // use the array_search function to check if the number entered is in the array
          if(in_array($numWanted, $numArray) )
          {
            echo "YES";
          }
          else
         {
            echo "NO";
          }
    ?>

  2. what if the it's like

    hey guys check out this site at http://www.frozenoven.com

    i wrote a similar script a while back here is a modified version

    <?php
    function link_url($url)
    {
    $url_href = substr($url, 0, 7) != "http://" ? "http://{$url}" : $url;
    return "<a href=\"{$url_href}\" rel=\"nofollow\">{$url}</a>";
    }
    echo "<pre>";
    $string = "hey guys check out this site at http://www.frozenoven.com http://www.test.com www.dsa.com www.asd.com";
    //for http://
    $count = substr_count($string, "http://");
    $start = 0;
    $len = 0;
    for ($i = 1; $i <= $count; $i++) {
    $start = strpos($string, "http://", $start + $len + 27);
    $len = strpos($string . " ", " ", $start) - $start;
    $url = substr($string, $start, $len);
    $string = str_replace(" " . $url, " " . link_url($url), $string, $asd);
    }
    //for www
    $count = substr_count($string, " www.");
    $start = 0;
    $len = 0;
    for ($i = 1; $i <= $count; $i++) {
    $start = strpos($string, " www.", $start + $len) + 1;
    $len = strpos($string . " ", " ", $start) - $start;
    $url = substr($string, $start, $len);
    $string = str_replace(" " . $url, " " . link_url($url), $string, $asd);
    }
    var_dump($string);
    ?>

     

    Scott.

    Or you could just do:

    <?php
    $subject = "hey guys check out this site at http://www.frozenoven.com";
    preg_match('/\\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/i', $subject,$matches);
    echo $matches[0];
    ?>

    Will echo http://www.frozenoven.co ;)

  3. while ($rows=mysql_fetch_assoc($validate))
    		{
    		$_SESSION['login']=TRUE;
    		$_SESSION['userid']=$row['id'];
    		$_SESSION['primeiro_nome']=$row['primeiro_nome'];
    		$_SESSION['ultimo_nome']=$row['ultimo_nome'];
    		$_SESSION['Email']=$row['Email'];
    }
    

     

    You're using $row when you should be using $rows.

    We can quite clearly see you should be using $rows but you're not.
    while ($rows=mysql_fetch_assoc($validate))
    		{
    		$_SESSION['login']=TRUE;
    		$_SESSION['userid']=$rows['id'];
    		$_SESSION['primeiro_nome']=$rows['primeiro_nome'];
    		$_SESSION['ultimo_nome']=$rows['ultimo_nome'];
    		$_SESSION['Email']=$rows['Email'];
    }

  4. Sorry, my above code should have been:

    $options = array("Lundi","Mardi","Mercredi","Jeudi","Vendredi");
    echo '<select class="label_form1 " name="Jour1">';
    foreach ($options as $k => $v)
    {  ?>
    <option value="<?php echo $v; ?>" <?php if ($_SESSION['Jour1'] == "Vendredi") {echo "selected" ; }?>><?php echo $v; ?></option>
    <?php
    }
    echo '</select>';

    Third time lucky lol, its late here:
    $options = array("Lundi","Mardi","Mercredi","Jeudi","Vendredi");
    echo '<select class="label_form1 " name="Jour1">';
    foreach ($options as $k => $v)
    {  ?>
    <option value="<?php echo $v; ?>" <?php if ($_SESSION['Jour1'] == $v) {echo "selected" ; }?>><?php echo $v; ?></option>
    <?php
    }
    echo '</select>';

  5. I think the point of the OPs post is to not allow people to post HTML tags to his/her script. I think we're deviating from the subject a bit. The facts of the matter are that the OP did not ask for the HTML to be shown in entity form,. but he DID ask for the HTML to be removed, which I think I have provided the code for.

  6. He never said anything about stripping tags. He said "remove html". Which is what htmlentities( ) will do.

     

    <span style="font-size:10px; font-weight:bold;">Hello <em>World</em></span>

     

    is not html.

    I think you'll find it is HTML but in its raw form. I think everyone else will agree with me that you're not actually removing anything at all. The OP should clarify.
  7. Or

     

    $string = htmlentities("<span style=\"font-size:10px; font-weight:bold;\">Hello <em>World</em></span>");
    echo $string;
    

     

     

    That will produce:
    <span style="font-size:10px; font-weight:bold;">Hello <em>World</em></span>

    which is not what the OP wants.

  8. That's what I feared you'd answer :P

    Thanks. There's no way a lazy programmer like myself will write 50 lines of code for that single purpose!

    Let's make a function to find out which option needs a "selected='true'"

     

    A loop ? hmm.

    How about javascript guys? do you think it could be easier to write a javascript to assign new values to the form?

    since javascript has acces to all page's elements

    I've already done that for you....
  9. Sorry, my above code should have been:

    $options = array("Lundi","Mardi","Mercredi","Jeudi","Vendredi");
    echo '<select class="label_form1 " name="Jour1">';
    foreach ($options as $k => $v)
    {  ?>
    <option value="<?php echo $v; ?>" <?php if ($_SESSION['Jour1'] == "Vendredi") {echo "selected" ; }?>><?php echo $v; ?></option>
    <?php
    }
    echo '</select>';

  10.        <select class="label_form1 " name="Jour1">
    	<option value="Lundi" <?php if ($_SESSION['Jour1'] == "Lundi") {echo $_SESSION['Jour1'] ; }?>>Lundi</option>
    	<option value="Mardi" <?php if ($_SESSION['Jour1'] == "Mardi") {echo $_SESSION['Jour1'] ; }?>>Mardi</option>
    	<option value="Mercredi" <?php if ($_SESSION['Jour1'] == "Mercredi") {echo $_SESSION['Jour1'] ; }?>>Mercredi</option>
    	<option value="Jeudi" <?php if ($_SESSION['Jour1'] == "Jeudi") {echo $_SESSION['Jour1'] ; }?>>Jeudi</option>
    	<option value="Vendredi" <?php if ($_SESSION['Jour1'] == "Vendredi") {echo $_SESSION['Jour1'] ; }?>>Vendredi</option>
    </select>

    Only other option is to do:

    $options = array("Lundi","Mardi","Mercredi","Jeudi","Vendredi");
    echo '<select class="label_form1 " name="Jour1">';
    foreach ($options as $k => $v)
    {
    echo '<option value="'.$v.'" '.if ($_SESSION['Jour1'] == '.$v.') {echo $_SESSION['Jour1'] .'>'.$v.'</option>';
    }
    echo '</select>';

  11. yes.

    In the page it is submitted to after validation have:

    session_start();
    foreach ($_POST as $k => $v)
    {
    if ($k != "submit")//excludes the submit button named "submit" change accordingly
      {
        $_SESSION[$k] = $v;
      }
    }
    

    That will assign every $_POST var a corresponding $_SESSION variable.

    Then it is just a case of:

    <?php
    session_start();?>
    <input class="label_form1" type="text" name="Prénom" value="<?php if ($_SESSION['Prénom']) {echo $_SESSION['Prénom']; }?>" /><br />
    

    Done.

  12. Sir, i say sir, you are a genius

    Thanks, as a side note.

    str_replace(' ', '', $string)

    is not required when using trim(). So use:

    <?php
    $string = " ";
    $string = trim($string);
    
    if(empty($string)) {
    
    echo "empty!";
    
    }
    
    else {
    
    echo "spacy, i say";
    
    }
    ?>

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