Jump to content

mbtaylor

Members
  • Posts

    96
  • Joined

  • Last visited

    Never

Everything 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. bugger knows then lol maybe someone else will enlighten us!
  3. Odd, only thing I can think is if its looking for false? 1=true, 0=false etc. Maybe the triple equal would sort that !== that does type check too I believe.
  4. if ($start_year % 4 == 0) { # the year is divisible by 4 }else{ # the year is not divisible by 4 } != 0 should work fine too (the opposite obviously).
  5. because the <? is contained in a string. Check out HEREDOC syntax in the php manual (explained in the print manual page)
  6. 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.
  7. Actually this is a bit better: %((http://)?(www)\.?[A-Za-z-]*\.?[A-Za-z-]{1,5})%
  8. <?php $url = "http://www.some-url.com"; $url = preg_replace ("%([http://]*[www]{3}.?[A-Za-z-]*.?[A-Za-z-]{1,5})%", "<a href='$1' title='$1' />$1</a>", $url); print ($url); ?>
  9. 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
  10. 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.
  11. 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 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.
  12. I dont thing sleep is counted in php script execution time, but I could be wrong.
  13. Aye, the MaxMind GeoIP Lite data + API would suit your needs well and its free
  14. Its the database of IP addresses that is important, how you access that is up to you. I believe you can get the Maxmind GeoIP lite data for free and in either csv or binary format. I personally use their API to access that but you could use sql statements I guess.
  15. %[<>\\\/:*?,|\"\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
  16. 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.
  17. Does it? * Reads manual page. Sorry to dupe your post then.
  18. 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 />"); } }
  19. 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)); } } ?>
  20. Wow theres a DATEDIFF function? * remembers to read up on all MySQL functions... I always did it the strtotime() way
  21. mbtaylor

    <select>

    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?
  22. 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.
  23. No they arnt. The while loop is looping through the database rows, the for loop is looping through the current database row.
  24. 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.
  25. 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.