-
Posts
1,842 -
Joined
-
Last visited
Posts posted by marcus
-
-
<?php $equation = "x^3 + 2x^2 + 5x - 3"; $solutions = 10; $new = str_replace(" ",null,$equation); $find = "/([a-z])\^([\d]+)/"; $repl = '\1<sup>\2</sup>'; $do = preg_replace($find,$repl,$equation); echo "<table border=\"0\" cellspacing=\"3\" cellpadding=\"3\" style=\"border:1px solid #000\">\n"; echo "<tr><td colspan=\"2\" align=\"center\"><b>".$do."</b></td></tr>\n"; echo "<tr><td align=\"center\">X</td><td align=\"center\">Y</td></tr>\n"; for($i=(0-$solutions);$i<=$solutions;$i++){ $xf = "/([a-z])\^([\d]+)/"; $xr = pow('\$1','\$2'); $xf2 = "/([\d]+)([x])/"; $xr2 = '\1*'.$i; $xf3 = "/([\d]+)\^([\d]+)/"; $xr3 = 'pow(\1,\2)'; $orange = preg_replace($xf2,$xr2,$new); #$apple = preg_replace($xf,$xr,$orange); $apple = preg_replace ("/([a-z])\^([\d]+)/","pow($1,$2)",$orange); $banana = preg_replace($xf3,$xr3,$apple); $final = str_replace("x",$i,$banana); echo "<tr><td align=\"center\" style=\"border:1px solid #000\">".$i."</td><td align=\"center\" style=\"border:1px solid #000\">".$final."</td></tr>\n"; } echo "</table>\n"; ?>
From the code you can see I'm making the equation's variable replaced with $i, how can I successfully create the exact output of each f(x) ?
-
works like a charm, thank you.
-
since the php regex forum doesn't seem to be ever-so popular i'd figure i would post here
personally i suck when it comes to regular expressions, so if anybody could lead me to a path where i can help understand them it would be great...
anyone, my problem is: i'm trying to convert such variables like x^y so that ^y would turn into <sup>y</sup>
So if the user inputted x^2 + 5x - 4 the output in HTML would read x<sup>2</sup> + 5x - 4, and along with more exponents like: x^3 + 3x^2 + 4x - 2 would be x<sup>3</sup> + 3x<sup>2</sup> + 4x - 2
-
Why don't you sort the numbers with the numbers and the words with the words, and just assign a key to them.
-
We established this previously.
$query .= implode(", ",$set) . " WHERE `which_month` = '".$this_month."'";
-
-
Yes, you really only need mysel_real_escape_string and trim, to further your protection you could use strip_tags, htmlentities or any form of removing unwanted items when display your data.
-
What revraz said
It's common to forget quotes, just use them when you can to escape information, makes error checking a lot easier
-
Keep in mind, the only time you want to really use stripslashes is when you're outputting data from your database.
-
echo nl2br($input,false);
if that method fails for you
$l = str_replace("\r\n","<br>",$line);
-
You can't redefine a function like that.
function protect($input){ return mysql_real_escape_string(trim(strip_tags($input))); } $subject = protect($_POST['subject']); $comment = protect($_POST['comment']);
-
$consultsql = "SELECT * FROM `staffsched` WHERE `which_month`='".$curr_month."'";
-
mysql_real_escape_string will add backslashes to unwanted and possibly bad characters. (the best)
trim doesn't really do much but turn " something " into "something" by removing the spaces and tabs around it.
stripslashes is bad when tryin to protect your data in URLs, why? because if they found out you used just stripslashes on your variables and nothing else then they would simply just add slashes to be removed.
function protect($input){ return mysql_real_escape_string(trim(strip_tags($input))); }
imo that's sufficient.
-
Um, the foreach statement splits each of the usernames into a new "variable" which then would create a new row for each of the member (hence for each)
-
Well if you were to send multiple messages as once you could just do something like
<?php $to = $_POST['to']; $e = explode(";",$to); foreach($e AS $f){ if(is_user($f)){ // fake function // insert a message for everybody } } ?>
-
you can try this
<?php $items = $_POST['items']; $item = array(); $meal = array(); if(count($items) == 5){ foreach($items AS $itemz){ if(is_int($itemz)){ $item[$itemz] = $order->getItemByIndex($itemz); $meal[$itemz] = $item[$itemz]->getID(); } } if(count($item) == 5){ echo "GREAT SUCCESS"; }else { echo "something went terribly wrong..."; } }else { echo "you must select FIVE, not four, not six, but FIVE meals!"; } ?>
-
When creating this keep in mind all the fields.
Your PM table should be set up something like this:
id - int(11) - primary key - auto_increment
to - int(11)
from - int(11)
subject - varchar(64)
message - text
status - int(1)
date - varchar(64)
time - int(24)
status would be used to define the viewership of it, Unread, Read, Replied, so 0 = Unread, 1 = Read, 2 = Replied
When viewing the inbox you just have to know how you want it set up.
-Subject- / -From- / -Date Sent- / -Status- / -Delete-
And selecting the messages
$sql = "SELECT * FROM `pm_table` WHERE `to`='".$_SESSION['uid']."' ORDER BY time DESC LIMIT 15";
and you could probably go about from there on your own
-
<?php session_start(); print_r($_SESSION); if($_SESSION['clicks'] >= 0){ $_SESSION['clicks'] += 1; }else { $_SESSION['clicks'] = 0; } $urls = array(0 => 'http://google.com', 1 => 'http://yahoo.com', 2 => 'http://msn.com', 3 => 'http://omgpie.com'); echo "<a href=\"".$urls[$_SESSION['clicks']]."\">".$urls[$_SESSION['clicks']]."</a>\n"; ?>
-
Well if you don't want your site to be in their history you can try using
<meta http-equiv="cache-control" content="no-cache">
in your html head tags
-
<?php ob_start(); $file = $_GET['file']; if(file_exists($file)){ header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); }else { echo "File does not exist"; } ob_end_flush(); ?>
-
Well if either of your variables are arrays you can use natcasesort to sort them.
-
<?php $phones = $_POST['phone']; $new = ""; $x = 1; $c = count($phones); foreach($phones AS $phone){ $pipe = ($x == $c) ? "" : "|"; $new .= $phone . $pipe; $x++; } ?>
Use $new as your input value, then when you wanna select it just explode it with |
-
@Dj Kat
You're better off sending the URL and the params separately.
var url = 'page.php'; var params = 'val1=something&val2=somethingelse';
Then you would open the URL with post or get, and lastly send the params.
var http; // then make you necessary xml request type var url = 'page.php'; var params = 'val1=something&val2=somethingelse'; http.open("POST",url,true); http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.setRequestHeader("Connection", "close"); http.onreadystatechange = somefunction; http.send(params);
-
Your code is confusing from the get-go
<?php if (isset($_POST['user_id'])) { $user_id = mysql_real_escape_string($_POST['user_id']); $query = "SELECT id FROM user WHERE id ='" . $user_id . "'"; $result = mysql_query($query) or die(mysql_error()); // If the user was found, if (mysql_num_rows($result) < 1) { error_message("Your Account number was NOT found in our database!"); } else { $row = mysql_fetch_assoc($res); if ($row['name'] == $_SESSION['name']) { $query2 = "SELECT * FROM user WHERE username = '" . $row['name'] . "'"; $result2 = mysql_query($query2) or die("Couldn't execute query for collecting your data."); $row2 = mysql_fetch_assoc($result2); if ($row2['id'] != $user_id) { error_message("Sorry your inserted Account number does not match with your username"); } else { #Query = INSERT . . . . . } } } } ?>
convert formula into generated outputs
in PHP Coding Help
Posted
Don't see how that's going to help me.