Jump to content

marcus

Members
  • Posts

    1,842
  • Joined

  • Last visited

Posts posted by marcus

  1. <?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) ?

  2. 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

  3. 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.

  4. 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
    }
    }
    ?>

  5. 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!";
    }
    ?>

  6. 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

     

  7. <?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();
    ?>

  8. @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);

     

     

  9. 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 . . . . .
                }
            }
        }
    }
    ?>

×
×
  • 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.