laffin
Members-
Posts
1,200 -
Joined
-
Last visited
Everything posted by laffin
-
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>"; } }
-
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
-
[SOLVED] How do I search a PHP echoed list of numbers?
laffin replied to bobleny's topic in PHP Coding Help
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. -
[SOLVED] How do I search a PHP echoed list of numbers?
laffin replied to bobleny's topic in PHP Coding Help
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++; } ?> -
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);
-
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.
-
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.
-
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.
-
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
-
[SOLVED] Counting the biggest number of entries in a field!
laffin replied to budimir's topic in PHP Coding Help
$sql = "SELECT ID,COUNT(*) as highest FROM table GROUP BY ID"; -
[SOLVED] C++ Programming Question
laffin replied to Ninjakreborn's topic in Other Programming Languages
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. -
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.
-
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]
-
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.
-
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]
-
LOL Now that is funny way of doing a check.
-
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.
-
Anyone knows how to use preg_match exactly and could explain please?
laffin replied to yanivkalfa's topic in Regex Help
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. -
Unset question or something to clear variables.
laffin replied to Beauford's topic in PHP Coding Help
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. -
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
-
use the modulus operator for($i=1;$i<12;$i++) echo "$i" . (($i % 3)?' . ':'<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]
-
heh, I like that method as well. Thanks for the tip
-
ahhh than use array_combine $narray=array_combine($array1,$array2); foreach($narray as $key => $item) echo "<a href=\"$key\">$item</a>";
-
<?php $url=$_GET['url']; unset($_GET['url']); foreach($_GET as $name=>$value) { $param[] = $name.'='.$value; } $url .= "?" . implode("&",$param); echo $url; ?>
-
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";