-
Posts
79 -
Joined
-
Last visited
Everything posted by infid3l
-
Here's a function I wrote that you might find useful: <?php function GetBetween($find1, $find2, $string) { $parse = explode($find1, $string, 2); $parse = substr($parse[1], 0, stripos($parse[1], $find2)); return $parse; } print GetBetween("<b>", "</b>", "<b>DATA</b>"); // prints "DATA" ?>
-
If you only need to return X amount of results, always add this to the end of your SQL query: LIMIT x For example: SELECT username FROM user_db WHERE name='Ted' LIMIT 5
-
<?php $contents = file_get_contents("http://www.google.com"); file_put_contents("saved.html", $contents); ?>
-
I think you can run a SMTP server locally and do: jd2007@236.43.79.32 Or something like that. If you're interested in setting one up, I can help you out via MSN.
-
mySql and Visual basic
infid3l replied to logged_with_bugmenot's topic in Other Programming Languages
Although this forum deals with MySQL integration in PHP, I'll help you out: http://www.richtsoft.com/mysql_52_visual-basic.html Google is your friend. -
Unix timestamps? <?php if (($timestamp1 - $timestamp2) >= 172800) { // older than 2 days } ?> Otherwise: <?php if ((strtotime($timestamp1) - strtotime($timestamp2)) >= 172800) { // older than 2 days } ?> $timestamp1 being the larger value, of course.
-
I have no idea, but I do know that all timezones are compared to GMT (Greenwich Mean Time) which is 0. The offsets are measured in +# and -#. For the Western Hemisphere, you'll need these names: http://terra.gg.utah.edu/timezones.html
-
<?php print "<SELECT NAME='ZONE'>"; for ($i=-8;$i<=8;$i++) { if($i> 0) { print "<OPTION VALUE='$i'>Timezone: +$i</OPTION>\n"; } else { print "<OPTION VALUE='$i'>Timezone: $i</OPTION>\n"; } } print "</SELECT>"; ?> I don't think PHP gives their names. edit: Oops! fixed my mistake.
-
Your code gives an error. Parse error: syntax error, unexpected $end in C:\Documents and Settings\My Documents\xampp\htdocs\index.php on line 42 the code I supplied shouldn't give one, I tested it. Oh I see, what was the other error? His IF statements are hard to read.
-
I just posted that two replies up...
-
<?php $a= $_POST['a']; $b= $_POST['b']; $c= $_POST['c']; function quadratic ($a, $b, $c, $root) { { $precision = 3; // Change this value for a different decimal places rounding. $bsmfac = $b*$b-4*$a*$c; if ($bsmfac < 0) { // Accounts for complex roots. $plusminusone = " + "; $plusminustwo = " - "; $bsmfac *=-1; $complex=(sqrt($bsmfac)/(2*$a)); if ($a < 0){ //if negative imaginary term, tidies appearance. $plusminustwo = " + "; $plusminusone = " - "; $complex *= -1; } // End if ($a < 0) $lambdaone = round(-$b/(2*$a), $precision).$plusminusone.round($complex, $precision).'i'; $lambdatwo = round(-$b/(2*$a), $precision).$plusminustwo.round($complex, $precision).'i'; } // End if ($bsmfac < 0) else if ($bsmfac == 0) { $lambdaone = round(-$b/(2*$a), $precision); $lambdatwo = round(-$b/(2*$a), $precision); } // End else if (bsmfac == 0) else { $lambdaone = (-$b+sqrt($bsmfac))/(2*$a); $lambdaone = round($lambdaone, $precision); $lambdatwo = (-$b-sqrt($bsmfac))/(2*$a); $lambdatwo = round($lambdatwo, $precision); } if ($root == 'root1') {return $lambdaone;} if ($root == 'root2') {return $lambdatwo;} if ($root == 'both') {return $lambdaone. ' and ' .$lambdatwo;} } // End function ?>
-
function quadratic ($a, $b, $c, $root) {
-
[SOLVED] Grabbing/reading a text file from another server
infid3l replied to policosmos's topic in PHP Coding Help
You can just do: $html = file_get_contents("http://www.ndbc.noaa.gov/data/realtime2/41004.spec"); or: $html = implode('', file('http://www.ndbc.noaa.gov/data/realtime2/41004.spec')); btw your problem was you had the "http://" in the host, which fsockopen() doesn't like. and, $request = "GET $page HTTP/1.0&#92;r&#92;n"; $request .= "Host: $host&#92;r&#92;n"; $request .= "Referer: $host&#92;r&#92;n"; should have been: $request = "GET $page HTTP/1.1\r\n"; $request .= "Host: $host\r\n"; $request .= "Connection: Close\r\n\r\n"; -
WHERE forum_id=$id ORDER BY sticky DESC, recent DESC is identical to WHERE forum_id=$id ORDER BY sticky,recent DESC
-
Try changing: $num = mysql_numrows($pmnum); to $num = mysql_num_rows($pmnum);
-
[SOLVED] Like foreach, but I only want it happening a few times.
infid3l replied to jlange's topic in PHP Coding Help
You could do something like: <?php $count = 0; foreach ($value as &$val) { //code if ($count >= 5) { break; } else { $count++; } } ?> But if you don't need to use foreach: <?php for($i=0;$i<5;$i++){ print $array[$i]."<br>"; } ?> -
You could check if $album['image_name'] holds a value, and if not, make give it a value like "blank.gif" with just a white square or something. <?php if (!$album['image_name']) { $album['image_name'] = "blank.gif"; } ?>
-
Ohh I see. You're using || which means OR. You need to use && (and): <?php $ok = 60; if (($ok>=30) && ($ok<=50)){ print "30-50"; } else { print "60-over"; } ?>
-
Sorry, my C programming days kind of blended in with PHP. Look at the modified code above.
-
<?php $ok = 60; if (($ok>30) || ($ok<=50)){ print "30-50"; } else { print "60-over"; } ?>
-
[SOLVED] Only viewable if comming from a certain page?
infid3l replied to Northern Flame's topic in PHP Coding Help
<?php if (stripos($_SERVER['HTTP_REFERER'], "http://www.mysite.com/page1.php")) { // show content } else { // get out of here! } ?> -
Get the name of the file - but ONLY the file
infid3l replied to deadonarrival's topic in PHP Coding Help
There may/must be, but you could do this: <?php $filename = explode("/", $_SERVER['PHP_SELF']); $filename = $filename[count($filename)-1]; ?> -
<?php header("Content-Type: image/png"); $txt = "testing"; $im = imagecreatefrompng("http://beta.alabamaweather.org/radar/radarimages/background.png"); $white = imagecolorallocate($im, 255, 255, 255); imagettftext($im, 12, 0, 10, 15, $white, "arial.ttf", $txt); imagepng($im); ?> I don't know why you chose to make "testing" a constant or why you put $txt in date(), but try the code above.
-
I see this in the headers: Content-Type: text/html Should be "image/png" I edited the code I posted earlier, try it again.
-
That's why I linked to the manual. But I'll be nice this time: <?php header("Content-Type: image/png"); $im = imagecreatefrompng("background.png"); $white = imagecolorallocate($im, 255, 255, 255); imagettftext($im, 12, 0, 10, 15, $white, "times.ttf", date()); imagepng($im); ?> Upload your font ("times.ttf") into the same directory as the script and "background.png".