Jump to content

mbtaylor

Members
  • Posts

    96
  • Joined

  • Last visited

    Never

Posts posted by mbtaylor

  1. Heres my version...

     

    function limit_string($string, $charlimit){
       if(substr($string,$charlimit-1,1) != ' ')   {
           $string = substr($string,'0',$charlimit);
           $array = explode(' ',$string);
           array_pop($array);
           $new_string = implode(' ',$array);
           return $new_string.'...';
       }else{   
          return substr($string,'0',$charlimit-1).'...';
       }
      }
    

  2. Not too sure that this is what you mean but this is how I generate dynamic XML from a php page:

     

    <?php
    $xml =<<<XML
    <?xml version="1.0" encoding="utf-8"?>
    <products>
      <product>
         <name>Some Product</name>
         <name>1.99</name>
      </product>
    </products>
    XML;
    
    print ($xml);
    
    header( "Content-type: application/xml; charset=\"iso-8859-1\", true");
    header("Pragma: no-cache");
    ?>
    

     

    The XML would likely come from a database.

  3. Heh I wrote a different one...

     

    <?php
    $url = "http://www.some-url.com";
    $url = preg_replace ("%(http://www.?[A-Za-z-]*.?[A-Za-z-]{1,5})%", "<a href='$1' title='$1' />$1</a>", $url);
    print ($url);
    ?>
    

     

    I like your use of \w\d  - you also need to allow for a hyphen in the character range though.

     

    Regular expressions rule :)

  4. Thanks, i've read up in google and a couple of my programming books.

     

    The lightbulb just hasn't clicked on yet the way it works from one page to the next in verifying if the variable has been passed.

     

    Regarding Login, yes, I've used in login but this isn't a login. Although it's a membership purchase, the member doesn't establish a un and pw. They pay from a purchase.php page, which if approved to to the thankyou.php page which has three choices to select to fill out an informational form.

     

    I'm trying to keep access to the thankyou.php page except by way of the purchase.php page.

     

    If the user pays for your product and doesnt have a login, how are you going to know in future that they have paid?

    I would generate them a username/password based on their email address and email them it, then they can login with the details and access whatever they paid for.  You are going to need to store these details in a database which can be looked up in the login function to check payment status and other user details.

     

    If someone pays you could log them in automatically with a session. Maybe set that on the thankyou page and provide a link to the download page, or whatever.

     

     

     

  5. Well traditionally before page1.php you would have login.php which would ask for the username, password and match it against the database values. If correct then a session variable is created saying loggedin or whatever and then a simple function can be called on each page to check whether or not the user is logged in. I would personally put that in a header include or similar.

     

    Added:

     

    Oops reading your post again thats maybe not what you want :P In that case set a session to contain an array of referrers maybe and check the array to see if the neccessary pages are contained within.

  6. Doesn't seem to match on \

     

    %[<>\\\/:*?,|\"\s]%

     

    An easier way to avoid special (non-letter) characters is to use /\W/, or /\P{L}/ if you're Unicode friendly. It may be easier to establish what you want to allow, instead of what you don't.

     

    Ive not heard of that (/\W/), im going to have to read your regex post links Effigy :)

  7. Im not sure about ereg but with preg it would be something like:

     

    $string = "<test?>";
    preg_match ("/[<>\\/:*?,|\"\s]/", $string, $matches);
    print_r ($matches);
    
    if (count($matches) > 0) {
    # match
    }
    

     

    Would this not be more useful as a preg_replace though? Not knowing what you are trying to do exactly... preg_replace would string the chars out of your string.

  8. You could write a function which uses explode to split the string on a space which would create an array of words. Then loop through the array and insert a <br /> every Nth word.

     

    e.g

     

    $words = explode (" ", $string);
    $numtoseparate = 10; #number of words before inserting a <br />
    
    foreach ($words as $word) {
    $i++;
    print ($word);
    if ($i == $numtoseparate) {
       print ("<br />");
    } 
    }
    

  9. Heres a nice mcrypt class for you (mcrypt allows de-encryption).

     

    <?
    /***************************************************************
    Data encryption class
    ***************************************************************/
    /* usage example : 
    $encryption = new ubercrypt();
    $encryption->$key = "RQ2ByIw4g6u7FqLvtS+Nw1+tCRQaZKNf";
    $encryption->$encrypt_text = "secret";
    $password = $encryption->encrypt();
    echo ("encrypted pass = ".$password."<br />");
    echo ($encryption->decrypt($password));
    */
    class ubercrypt {
    var $key;
    var $encrypt_text;		
    var $decrypt_text;		
    function encrypt(){
              $key = $this->$key;
              $input = $this->$encrypt_text;			
              $input = str_replace("\n","",$input);$input = str_replace("\t","",$input);$input = str_replace("\r","",$input);
              $key = substr(md5($key),0,24);
              $td = mcrypt_module_open ('tripledes', '', 'ecb', '');
              $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
              mcrypt_generic_init ($td, $key, $iv);
              $encrypted_data = mcrypt_generic ($td, $input);
              mcrypt_generic_deinit ($td);
              mcrypt_module_close ($td);
              return trim(chop(base64_encode($encrypted_data)));
    }
    function decrypt($input){
              $key = $this->$key;
              $input = str_replace("\n","",$input);$input = str_replace("\t","",$input);$input = str_replace("\r","",$input);
              $input = trim(chop(base64_decode($input)));
              $td = mcrypt_module_open ('tripledes', '', 'ecb', '');
              $key = substr(md5($key),0,24);
              $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);
              mcrypt_generic_init ($td, $key, $iv);
              $decrypted_data = mdecrypt_generic ($td, $input);
              mcrypt_generic_deinit ($td);
              mcrypt_module_close ($td);
              return trim(chop($decrypted_data));
         } 	
    }
    ?>
    

  10. Use a foreach loop to loop through as associative array. You can use $var => $value to look through all the keys.

     

    foreach ($_POST as $var => $value) {
    # loop through post vars and add up anthing that has "VB" in the variable name.
      if (strstr ($var, "VB")) {
        $total += $value;
      } 
    }
    
    if ($total > 0) {
    # user has made a purchase
    }
    
    /*
    Note if you did $$var = $value you would get the variable $VB0001 etc.
    */
    

     

    But then, why would a Select form field be submitting many VBXXXX values surely it would only be 1?

    If so you would access that with the name attribute of your select field e.g

     

    <select name='something'>
    
    $something = $_POST['something'];
    

     

    Does that help?

  11. there is no need to add a foreach loop inside a while loop... they do the exact same thing... you're just using up more resources.

    I'm pretty sure the foreach is so that if there is more then 1 row he is searching for in the query, it will display all of them, instead of just one.

     

    The while loop will loop through all rows. What I posted was a solution to what truegilly was wanting to do. I personally use the same to give me a quick idea of all the elements being pulled in from the db. The same could be achieved with print_r which I guess may be more efficient I dont know but less flexible certainly.

  12. Well its an array so just use a for loop to show the elements you want.

     

    For example:

     

    $numelements = count ($arrImages);
    for ($i=0;$i<3;$i++) {
    print ($arrImages[$i]);
    # prints out first 3 elements
    }
    
    for ($i=3;$i<6;$i++) {
    print ($arrImages[$i]);
    # prints out elemets 3 - 6
    }
    

     

    Hope that helps.

     

  13. You mean you want the array sorted?

     

    $arrImages = array();
        if (is_dir($dir)) {
          if ($dh = opendir($dir)) {
          while (($file = readdir($dh)) !== false) {
          // Is it a valid extension?
          if(!is_dir($file) && is_numeric(strpos($file, "."))) {
            if($this->_IsValidExtension($file))
            $arrImages[] = $file;      
            }
          }
          closedir($dh);
        }
      }
      array_multisort ($arrImages, SORT_DESC, SORT_STRING);
      //or array_multisort ($arrImages, SORT_ASC, SORT_STRING);
      $num_elements = count ($arrImages);
      array_splice ($arrImages, 10, $num_elements);
    

     

    This is untested code, but I am basically using array_multisort to sort the elements then splicing anything over 10.

    Good luck!

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