-
Posts
9,409 -
Joined
-
Last visited
-
Days Won
1
Everything posted by MadTechie
-
Revised edition: cleans up commas etc <?php $flavor[] = "mustard"; $flavor[] = "bbq"; $flavor[] = "ketchup"; $flavor[] = null; //debug testing $flavor[] = "super mustard"; flavors(); function flavors () { global $flavor; //not sure why you have a checkbox counter! //$i = 3; // counter for the number of checkboxes minus 1 for the array //rebuild clean array $cflavor = array(); foreach($flavor as $f) { if (!is_null($f)) $cflavor[] = $f; } $flavor = $cflavor; unset($cflavor); $c = count($flavor);// counter $counter = 0; foreach($flavor as $f) { if ($c > 1) //updated { $counter++; if ($counter < $c) { echo $f; echo ($counter == ($c-1)?" ":", "); }else{ echo "or $f "; } }elseif ($c == 1){ echo ("$f only please"); } } } ?> Also if this is solved please click topic solved bottom left
-
Okay heres my test script.. <?php $flavor[] = "mustard"; $flavor[] = "bbq"; $flavor[] = "ketchup"; $flavor[] = null; //debug testing $flavor[] = "super mustard"; flavors(); function flavors () { global $flavor; //not sure why you have a checkbox counter! //$i = 3; // counter for the number of checkboxes minus 1 for the array $c = count($flavor);// counter $counter = $c; foreach($flavor as $f) { if ($c > 1) //updated { $counter--; if ($counter > 0) // I think this is where some of the problem is { if (!is_null($f)) { echo ("$f, "); } }else{ echo ("or $f "); } }elseif ($c == 1){ echo ("$f only please"); } } } ?>
-
try this <?php $apps = mysql_query("SELECT signupid,name,gamename,sn,email,pass,position,info,time,ip FROM apply") or die(mysql_error()); while ($apps = mysql_fetch_array($apps)){ ?> whats the error ?
-
i am not sure what your asking for exactly.. i think you mean this <?php function flavors () { global $flavor; $i = 3; // counter for the number of checkboxes minus 1 for the array $c = 0; // counter /*foreach($flavor as $f) { $c++; }*/ // replaced $c = count($flavor); if ($c !=1) { foreach($flavor as $f) { if ($i > 0) { if ($flavor[$i] != NULL) { echo ("$f, "); $c= $c-1; $i = $i-1; } }else{ echo ("or $f "); } } }elseif ($c == 1){ echo ("$f only please"); //echo ("<br> i= $i"); //echo ("<br> c= $c"); } } ?>
-
try this <?php $users = array(); $users["bob1"] = "bobpass1"; $users["bob2"] = "bobpass2"; $users["bob3"] = "bobpass3"; $users["bob4"] = "bobpass4"; $valid = false; if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) { if(array_key_exists($_SERVER['PHP_AUTH_USER'],$users)) { $valid = ($users[$_SERVER['PHP_AUTH_USER']] == $_SERVER['PHP_AUTH_PW']); } } if(!$valid) { header('WWW-Authenticate: Basic Realm="Secured Area"'); header('Status: 401 Unauthorized'); } else { echo "You are in!"; } ?> **untested
-
True, but the code above is old (php 4 version) imagefilter came out in php5
-
welcome review previous post for some detail
-
just clears the REFERER and examine the last requests filetime before requesting another uri See human comments (hope it makes sense) <?php curl_setopt($ch, CURLOPT_FILETIME, true); //My Habbit curl_setopt($ch, CURLOPT_REFERER,""); //I belong here curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)"); //Im not scrapping i am a browser ?>
-
wrong section.. please use the Javascript section
-
Not sure what you asked then.. if you had permission they would give you a link to use (probably an XML file) as your scrapping i assume you don't have permission.. so they have added a anti leaching procal you can get around it by adding one line of code to your existing code.. ahh whatever try this <?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.bloomberg.com/markets/commodities/energyprices.html"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FILETIME, true); curl_setopt($ch, CURLOPT_REFERER,""); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)"); $contents = curl_exec($ch); curl_close($ch); $find1 = find_values('Nymex Crude Future', $contents); echo "Nymex Crude Future: Price = $find1[0], Change = $find1[1], & Change = $find1[2], Time = $find1[3]<br>"; $find2 = find_values('Dated Brent Spot', $contents); echo "Nymex Heating Oil Future: Price = $find2[0], Change = $find2[1], & Change = $find2[2], Time = $find2[3]<br>"; $find3 = find_values('WTI Cushing Spot', $contents); echo "Nymex RBOB Gasoline Future: Price = $find3[0], Change = $find3[1], & Change = $find3[2], Time = $find3[3]<br>"; function find_values ($string, $page) { $string = preg_quote($string, '#'); // takes everything from the given string to end of row preg_match("#$string(.*)</tr>#Us", $page, $match); // Get the values from the row we found previously preg_match_all("#<span[^>]*>([^<]*)</span>#s", $match[1], $values); // Return the values return $values[1]; } ?> EDIT: Opps wrong one! updated
-
They have added an "anti-leaching" protocal, you can get around it (one line of code infact) but i am guessing you don't have permission to use their data!
-
i was about to say.. the code is fine.. how are you calling it <?php #class userquery { //This Fucntion Is Used To Check Weather User as an Admin has Been Logged in or Not function admin_login_check() { $userid = $_COOKIE['userid']; $username = $_COOKIE['username']; $session = $_COOKIE['PHPSESSID']; $query = mysql_query("SELECT * FROM admin WHERE username = '".$username."' AND session = '".$session."'"); if(mysql_num_rows($query) == 1) { $login = true; }else{ $query = mysql_query("SELECT * FROM users WHERE level='".$admin."' AND username ='".$username."' AND userid = '".$userid."' AND session='".$session."'"); if(mysql_num_rows($query) == 1) { $login = true; }else{ header('location:login.php'); } } } #} admin_login_check(); echo "Loggedin"; ?> also i tested it in firefox! Global Reg problem ?
-
yes do i know, but this is for helping with current script problems not a site for getting scription written for you.. But Heres a starting block.. this will convert color to grayscale..its not great needs a few improvments (as the quality drops if used over and over) but it works.. you should be able to alter this to suite your needs <?php function convert($filename) { $filename = imagecreatefromjpeg($filename); list($width, $height) = getimagesize($filename); $bwimage= imagecreate($width, $height); for ($c=0;$c<256;$c++) { $palette[$c] = imagecolorallocate($bwimage,$c,$c,$c); } //Reads the origonal colors pixel by pixel for ($y=0;$y<$height;$y++) { for ($x=0;$x<$width;$x++) { $rgb = imagecolorat($source,$x,$y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> & 0xFF; $b = $rgb & 0xFF; //This is where we actually use yiq to modify our rbg values, //and then convert them to grayscale palette $gs = $this->yiq($r,$g,$b); imagesetpixel($bwimage,$x,$y,$palette[$gs]); } } // Outputs a jpg image, but you can change this to png or gif if that is what you are working with imagejpeg($bwimage, $filename); imagedestroy($bwimage); } ?> hope this helps
-
Erm... back to the books then (or the freelance section)
-
sure.. see here and here anymore homework please mail me on junkmail@nothome.com
-
ahh use preg_match_all <?php $entry = "[color=000000]some text[/color] and [color=FF0000]other text[/color]"; preg_match_all('%\[color\=(.*?)\](.*?)\[\/color\]%si', $entry, $result, PREG_SET_ORDER); foreach($result as $r) { echo "color: ".$r[1]; //Color echo "<br>text: ".$r[2]; //text echo "<br>---<br>"; } ?>
-
php is parsed so providing you don't echo the data you wish to hide theirs no problem.. also if some gain that level of access to read the php file it doesn't matter where their are!
-
have you tried adding error_reporting(E_ALL); also are you sending any data to the page ie any HTML etc
-
<?php $entry = "[color=AABBCCDD]The Text[/color]"; if ( preg_match( '/\[color\=(.*?)\](.*?)\[\/color\]/i', $entry, $matches ) ) { echo "color: ".$matches[1]; //Color echo "<br>text: ".$matches[2]; //text } ?>
-
Not an empty table but a html page that contains the Just the table, no banner not menu etc just a "basic page" table with data..
-
Okay.. try this.. change the output, to ONLY echo the table and try printing that page.. if that works you may need to have a "print friendly Page" for printing.. does that make sense ? also this may be useful http://www.printer-friendly.com/
-
can you provide a link, or something we can see
-
[SOLVED] Memory efficient coding practice - thoughts please
MadTechie replied to littledragon's topic in PHP Coding Help
benchtesting time.. create a massive array (use a loop) then pass ie into a function 40000000 times (with a returning the same var) check memory usage and execution time.. i'll love to know -
[SOLVED] Memory efficient coding practice - thoughts please
MadTechie replied to littledragon's topic in PHP Coding Help
i am guessing your asking if its more memory efficient to pass the whole array and then the function pulls out the "correct" item and uses it ~or~ workout the correct item then only pass that to the function to use! if this is what your asking then i think passing the item would be better but it would be even better to setup a class and set it as public array and refer to that.. hope that helps EDIT: typos -
rest of what? i don't really see a question ! i think you want 2 tables and want to search one.. this is the basics of SQL.. but again i can't see the part your stuck on !