Jump to content

xiaix

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Everything posted by xiaix

  1. Yep, that works great. It's better than what I was starting to do... $a = "abcDEF"; $b = "abcDEF"; $lenA = strlen($a); $lenB = strlen($b); if ($lenA != $lenB) { echo "Diff Len, no need to continue."; exit(); } $data1 = preg_split("//", $a); $data2 = preg_split("//", $b); $len = $lenA; $found = 0; for ($x = 1; $x <= $len; $x++) { $found = 0; for ($y = 1; $y <= $len; $y++) { if ($data1[$x] == $data1[$y]) { $found = 1; break; } } if ($found == 0) break; } if ($found == 0) echo "No match"; Which wasn't quite working anyway.
  2. Best method to for the following? // The following $str1 and $str2 should say they are identical $str1 = "abcDEF"; $str2 = "EcFabD"; // The following $str1 and $str2 should say they are NOT identical because of the "a" "A" case difference. $str1 = "abcDEF"; $str2 = "EcFAbD"; I'm comparing bitvector strings. "ABC" is different than "abc". "abc" is the same as "cba". What's the best php function or method I should use? Thank you.
  3. *update* <pre> tags got messy, and after much trying to get things to pad correctly, I gave up and opted for table/row/columns to handle my text padding/justification issues. Everything works great now. Example: // Let's list armor defenses if ($howManyArmorDef>0) { $part .= sprintf("<BR /><strong>Defenses</strong><BR />"); $part .= sprintf("<table>"); if ($data1["e"] > 0) { $part .= sprintf("<tr><td>%+d</td><td>[%s]</td></tr>", $data1["e"], $defType["e"]); } if ($data1["f"] > 0) { $part .= sprintf("<tr><td>%+d</td><td>[%s]</td></tr>", $data1["f"], $defType["f"]); } if ($data1["g"] > 0) { $part .= sprintf("<tr><td>%+d</td><td>[%s]</td></tr>", $data1["g"], $defType["g"]); } if ($data1["h"] > 0) { $part .= sprintf("<tr><td>%+d</td><td>[%s]</td></tr>", $data1["h"], $defType["h"]); } if ($data1["i"] > 0) { $part .= sprintf("<tr><td>%+d</td><td>[%s]</td></tr>", $data1["i"], $defType["i"]); } if ($data1["j"] > 0) { $part .= sprintf("<tr><td>%+d</td><td>[%s]</td></tr>", $data1["j"], $defType["j"]); } $part .= sprintf("</table>"); }
  4. Ah, gotcha. I was scratching my head for hours as to why it wouldn't work. Didn't know that HTML wouldn't display padding like that. I'll use your advise with the <pre / > tags. Thanks for the quick response.
  5. This code: if ($data1["e"] > 0) { $part .= sprintf("<strong>%s %d %s</strong>", $data1["e"] > 0 ? "+":"-", $data1["e"], $defType["e"]); if ($howManyArmorDef > ($e1 += 1)) { $part .= "<BR />"; }} Displays this: +54 Melee Piercing Defense Fine, but if I use this code (notice the %5s): if ($data1["e"] > 0) { $part .= sprintf("<strong>%s %d %5s</strong>", $data1["e"] > 0 ? "+":"-", $data1["e"], $defType["e"]); if ($howManyArmorDef > ($e1 += 1)) { $part .= "<BR />"; }} I still get this: +54 Melee Piercing Defense But I should get this: +54 Melee Piercing Defense What gives? What am I doing wrong? Thanks.
  6. You, my friend, are genius. Worked wonderfully. Thank you.
  7. Thank you for your very quick reply. I could see str_split() working like I needed if my string were a one-to-one ratio, like: a4b2c5 But will str_split() still work the way I need it to if my string is: a4b24854c555 ?
  8. I have a string coming in from a database. For example: a0b34c7d0e2333 What I would like to do is build an end result keyed array with that string, like this: $dataArray = array("a" => "0", "b" => "34", "c" => "7", "d" => "0", "e" => "2333"); Since I don't have a valid delimiter for the explode function to work, I would like to know if I can use the letters (alpha) of the incoming string as a delimiter. What coding hurdles would I need to convert my incoming string into that keyed array? Is it even possible to do this? I thank you for your time and review.
  9. Error (warning) message received: PHP Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in ... Setup: application.php <?php include($_SERVER['DOCUMENT_ROOT'] . "/config/siteConfig.php"); include(SESSION_CLASS); include(SITE_CLASS); include(DATABASE_CLASS); $mySession = new session(); $site = new site(); $db = new database(); $site->dbAccess("myDatabase"); $db->dbConnect("localhost", $site->dbUsr, $site->dbPas, $site->dbDB); $site->freeDBinfo(); if ((isset($_POST["insertData"])) && ($_POST["insertData"] == "formData")) { $insertSQL = sprintf("INSERT INTO application (First_Name, Last_Name) VALUES (%s, %s)", $db->GetSQLValueString($_POST['FIRST_NAME'], "text"), $db->GetSQLValueString($_POST['LAST_NAME'], "text")); $dbQueryResult = $db->dbQuery($insertSQL, $db->dbConID); } ?> // Blah blah, some html... <?php if ($db) $db->dbFree(); if ($db) $db->dbClose(); ?> database.class.php <?php function dbQuery($query, $dbConID) { $this->thisQuery = mysql_query($query, $dbConID); if (!$this->thisQuery) { die('Invalid query); } $subStr = strtoupper(substr($query, 0, 4)); switch($subStr) { case strstr(trim($subStr), "SEL"): case strstr(trim($subStr), "SHO"): $this->dbNumRows = mysql_num_rows($this->thisQuery); break; case strstr(trim($subStr), "INS"): case strstr(trim($subStr), "DEL"): case strstr(trim($subStr), "REP"): case strstr(trim($subStr), "UPD"): $this->dbNumRows = mysql_affected_rows($this->thisQuery); break; } return $this->thisQuery; } ?> The query inserts the record, no problem. I'm just wondering why I'm receiving the warning (as mentioned at the top of this post). If anyone needs to see more code, let me know. Thanks in advance.
  10. Ah, okay. Completely understandable. I did not realize that the httprequest instance was it's own separate process that did not tie into it's caller. Thank you very much for pointing that out.
  11. I understand. Again, my apologies for not being clear first time 'round.
  12. Okay, it does in fact work if I had the following: www/index.php <?php include($_SERVER['DOCUMENT_ROOT'] . "/config/config.php"); include(DATABASE_CLASS); ?> // Blah blah blah, some html, then... <?php include("onlineList.php"); ?> However, I do not. I apologize for not being clear. Here is what I have: www/index.php <?php include($_SERVER['DOCUMENT_ROOT'] . "/config/config.php"); include(DATABASE_CLASS); ?> <SCRIPT src='scripts/testScript.js' type='text/javascript'></SCRIPT> <SCRIPT LANGUAGE="JavaScript"> function startMe(file) { setTimeout("submitWhosOnline('"+file+"')", 0); } </SCRIPT> // Blah blah blah, some html, then... <DIV id="putItHere"> <script language="JavaScript"> startMe("onlineList.php"); </script> </DIV> www/scripts/testScript.js var xhr = false; var outMsg; var urlFile; function submitWhosOnline(file) { urlFile = file; if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else { if (window.ActiveXObject) { try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) { xhr = false; alert("There is no support for XMLHttpRequest with this browser."); } } } if (xhr) { xhr.onreadystatechange = showContents; xhr.open('GET', urlFile, true); xhr.send(null); } else { alert("Sorry, but I couldn\'t create an XMLHttpRequest"); } } function showContents() { if (xhr.readyState == 4) { if (xhr.status == 200) { outMsg = xhr.responseText; setTimeout("submitWhosOnline('"+urlFile+"')", 5000) } else { outMsg = "There was a problem with the request " + xhr.status; } } if (window.document.getElementById("putItHere") != null) { window.document.getElementById("putItHere").innerHTML = outMsg; } }
  13. I'm logging my errors. This is the error: PHP Fatal error: Class 'database' not found in C:\\Apache\\htdocs\\www\\onlineList.php on line 3, referer: http://www.mywebsite.com/ That is the only information that PHP is giving me.
  14. Here's the situation: www/config/config.php <?php // SITE_ROOT has to be set first define("SITE_ROOT", $_SERVER['DOCUMENT_ROOT']); // Class paths define("DATABASE_CLASS", SITE_ROOT . '/classes/database.class.php'); ?> www/index.php <?php include($_SERVER['DOCUMENT_ROOT'] . "/config/config.php"); include(DATABASE_CLASS); ?> // Blah blah blah, some html, then... <?php include("onlineList.php"); ?> www/onlineList.php <?php $db = new database(); $db->dbConnect(); $dbQueryResult = $db->dbQuery("SELECT * FROM characters WHERE loggedIn='1'", $db->dbConID); $dbRowResult = $db->dbGetRow($dbQueryResult); ?> And here's the error: PHP Fatal error: Class 'database' not found in C:\\Apache\\htdocs\\www\\onlineList.php on line 3, referer: http://www.mywebsite.com/ Yes, my database class is fine. In fact, if I do this: <?php include('classes/database.class.php'); // <---- SHOULD NOT HAVE TO HAVE THIS $db = new database(); $db->dbConnect(); $dbQueryResult = $db->dbQuery("SELECT * FROM characters WHERE loggedIn='1'", $db->dbConID); $dbRowResult = $db->dbGetRow($dbQueryResult); ?> ... then everything works fine. I would imagine it's a scope issue, but I just don't see why I have to add that include in my onlineList.php file, when it should have been taken care of it it's parent. Any suggestions as to what I'm doing wrong?
×
×
  • 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.