Jump to content

laffin

Members
  • Posts

    1,200
  • Joined

  • Last visited

Everything posted by laffin

  1. recursive functions array_string_display($array) { foreach($array as $item) { if(is_array($item)) array_string_display($array); else if(is_string($item)) echo "Oh I got one: $item<BR>"; } }
  2. preg_replace('/<a href="(.*)">/', "<a href='http://www.site.com/parse.php?url=".base64_encode($1)."'>", $string); i dun see how this works, preg replace needs the 2nd paramenter to be a string beforehand. it will not parse base64 while performing the repacement. <?php header("Content-type: text/plain"); $body='This is a string with a url in it <a href="http://www.google.co.uk/search?q=php&num=100&hl=en&safe=off&start=200&sa=N">http://www.google.co.uk/search?q=php&num=100&hl=en&safe=off&start=200&sa=N</a>'; echo $body."\n"; function urlencodebase64($matches) { $url=urlencode(base64_encode($matches[2])); return "<A HREF=\"http://my.site.com/parse.php?url=". $url ."\">"; } $body=preg_replace_callback('/(<a\s+.*href\s*=\s*"(.*)".*?>)/i','urlencodebase64',$body); echo $body."\n"; ?> which outputs
  3. ok, i see why now. didn hit me that the first pass is zeroed out to get the values. like using a do statement instead of a while statement.
  4. shudn there be an else in there <?php sort($arrData); // sort your array of numeric values $intCurrentValue = 0; $intDupCount = 0; for ($i = 0, $intCnt = count($arrData); $i < $intCnt; $i++) { if ($intCurrentValue != $arrData[$i]) { if ($intDupCount > 1) { echo $intCurrentValue; // displays number that appeared more than once } $intCurrentValue = $arrData[$i]; $intDupCount = 0; } else $intDupCount++; } ?>
  5. uhm, not quite, as that might also replace the minutes and seconds if they are 00 if(substr($blamtime,0,2)=="00") substr_replace($blamtime,"24",0,0);
  6. this is why i gave u a function to use function dateformat($from="",$format="M d, Y") { if(empty($from)) $ft=time(); else $ft=strtotime($from); return date($format,$ft); } it's a function, u call it from yer code, not change it (unless u know what u are doing). in my original post i gave an example of how to use it $sql = "SELECT * FROM tlb"; $result = mysql_query($sql, $conn); while ($row = mysql_fetch_array($result)) { $row['dt']=dateformat($row['dt']); } for a more precise description of what it does: dateformat converts a date string to another date format. the calling is simple $var=dateformat($olddate,$newformat) $var is the variable to hold the new date $olddate, is the variable holding the old date $newformat is how u want the new date to look like, use date function to help u try different formats. this parameter is optional as a default format is set in the function.
  7. I wudda continued to help however Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ']' in /home/usr/htdocs/linkexchangesystem/2.php on line 32 when u dun even attempt to fix the simplest of errors, than it's kinda pointless trying to show someone how to do something.
  8. nope not at regular intervals. well methods from their server. u can try doing it remotely, just by having an application check the url. WinCron tied in with a batch file and WGet for windows shud do the trick or if u have php on yer pc, wincron and a php script.
  9. I dun see why u need a recursive search function. the data y show looks like a standard data set. recursion comes when u have arrays in arrays in arrays, and must check up to the deepest nested array. it looks like all u need is a simple function to search for id's with a specific date function md_search($array, $fieldid, $what) { foreach($array as $key => $item) if($item[$fieldid]==$what) $found[]=$key; return $found; } now ya can find yer data with $keysofitems=md_search($array,'Date','2007-12-31'); which will return an array of keys
  10. $sql = "SELECT ID,COUNT(*) as highest FROM table GROUP BY ID";
  11. pause is supposed to be a program file (pause.exe) on windows. I guess Vista has removed this program. Some Nifty Command line utilities u can put these in yer program folder or in a folder that is in the path.
  12. Simple php code will not work in a HTML setting. and HTML will not work in a php setting. Thus the php tags that encases/seperates php code from html code. php can output html, it's the primary use. that's a bizarre trick u have going there, never seen it before.
  13. laffin

    security

    u have to secure / validate any external variables. example [code]<?php $number=$_GET['number']; echo "$number X 5 = ". $number*5; mysql_query("UPDATE table SET number=$number WHERE id=1"); ?> this is very insecure, because we didnt validate $number. in the echo statement a malicious user can insert some javascript, which cud lead to hacked accts. than u have it going to a MySQL statement, without proper validation/sanitization, u risk yer whole db to be hacked. <?php function validate_number($number,$min=0,$max=100) { $number=intval($number); if($number<$min) $number=$min; if($number>$max) $number=$max; return $number; } $number=validate_number($_GET['number'],1,10); echo "$number X 5 = ". $number*5; mysql_query("UPDATE table SET number=$number WHERE id=1"); ?> intval converts a value into an integer. what the script is expecting. the min/max is a sample of validating our extternal variable and forcing it to conform to what we expect it to be. There is a lot more to Injection attacks but this is just a simple example[/code]
  14. plenty of different ways for this question think of valid chars as cards. u can have it do one of 2 methods 1) Just use the cards, no repeats of cards, shuffle and deal 35 cards. 2) Put the cards in seperate piles, and open a few more decks and put them on each pile. pick a random pile, draw a card, and repeat 34 more times. this one is simple to do.
  15. function dateformat($from="",$format="M d, Y") { if(empty($from)) $ft=time(); else $ft=strtotime($from); return date($format,$ft); } $sql = "SELECT * FROM tlb"; $result = mysql_query($sql, $conn); while ($row = mysql_fetch_array($result)) { $row['dt']=dateformat($row['dt']); } [code] [/code]
  16. LOL Now that is funny way of doing a check.
  17. U can only detect things based on what is givin. not like yer script can check out a users pc and see what's running. all u have is what info is provided by yer webserver.
  18. first read a tutorial on regex patterns. Such as This Link Once ya have the concept of how regex patterns are used (it's okay if u dun know how to build em) than get a tool to help u design and test yer regex patterns (Expresso regex Development tool). Okay now ya kinda know the patterns and ya have a tool to build those patterns. Just a note: Expresso dusn use the start/end delimeters as preg functions nor does it have the options after the ending delimeter. so be shure to add/remove them when going from code to expresso and vice versa. Good luck.
  19. nope $_POST is sent by the browser someone hits refresh $_POST is resent by the browser so dun matter what yer script does. u have to setup an external variable, somehow. either by cookies, sessions, file or a db field.
  20. means yer using an earlier version of php. array_combine is in php5 now your options are either buiild a array_combine or use multi-dimensional arrays
  21. use the modulus operator for($i=1;$i<12;$i++) echo "$i" . (($i % 3)?' .&nbsp':'<BR>'); [code] which is basicly the same as keeping a counter [code] for($i=1,$counter=0;$i<12;$i++,$counter++) { echo "$i"; if($counter<3) echo " . "; else echo "<BR>"; } [/code][/code]
  22. heh, I like that method as well. Thanks for the tip
  23. ahhh than use array_combine $narray=array_combine($array1,$array2); foreach($narray as $key => $item) echo "<a href=\"$key\">$item</a>";
  24. <?php $url=$_GET['url']; unset($_GET['url']); foreach($_GET as $name=>$value) { $param[] = $name.'='.$value; } $url .= "?" . implode("&",$param); echo $url; ?>
  25. for some reason that code dun look right. defined("PAGE_NAME") && $_page = PAGE_NAME; defined("e_PAGETITLE") && $_page = e_PAGETITLE; ($_page != '') && $_page .= ' | '; //if variable is filled since there is no if structure testiing the expression. nor is it a valid assignment operation. and the one before echo "<title>".(defined("e_PAGETITLE") ? e_PAGETITLE.' | ' : (defined("PAGE_NAME") ? PAGE_NAME.' | ' : "")).SITENAME."</title>\n"; looks syntatically correct. and the expression is not mixing PHP & HTML, they are clearly seperated anyways to answer the question all u have to do is break down the string into it's different components echo "<title>". SITENAME. ( defined("e_PAGETITLE") ? e_PAGETITLE . ' | ' : ( defined("PAGE_NAME") ? PAGE_NAME.' | ' : "" ) ). "</title>\n"; once u have the different components of the string broken down ya can move the various pieces around echo "<title>". ( defined("e_PAGETITLE") ? e_PAGETITLE . ' | ' : ( defined("PAGE_NAME") ? PAGE_NAME.' | ' : "" ) ). SITENAME. "</title>\n";
×
×
  • 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.