Jump to content

MadTechie

Staff Alumni
  • Posts

    9,409
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by MadTechie

  1. Their is nothing wrong with the array or the loop (well kinda) the problem is you are terminating the loop without doing anything, So you are doing the loop without any output then displaying the last entry.. foreach($beatles as $roles => $names); should be (Note the semi-colon at the end) foreach($beatles as $roles => $names)
  2. Try this <a href="showthread\.php([^"]*)"[^>]*>([^<]+)</a>
  3. Oh I read the instructions wrong, its simpler than the code I wrong Details, okay first we create a small part of HTML code, but as we want the data to be dynamic we put some tags in the file that we can replace later (ACC and BAL), Then we create a HTML FORM (i assume you know how to do this), now the form has 2 inputs named account and balance, and the forms action is solution06.php, Now we write the PHP code to get the input from the FORM and get the HTML from the txt file and replace the known tags with the form data.. Okay first of all so, Step 1 - Create solution06.txt <P>This is the textfile that will display the results</P> <P>Account number is [ACCT] and balance is [bAL]</P> That's step 1 done. Step 2 - Create solution06.html Create a form that requires 2 inputs account number and balance Step 3 - Create solution06.php $pageBody = file_get_contents('solution06.txt'); //put file into variable //Get form data $account = $_POST['account']; $balance= $_POST['balance']; //Replace data in text file from with form data $pageBody = str_replace("[ACC]", $account, $pageBody); $pageBody = str_replace("[bAL]", $balance, $pageBody); echo $pageBody; Okay i hope that has helped
  4. okay.. without knowing more about the doPost function its kinda hard to say what that call does!.. so can you post that script or atleast what variable is being set
  5. okay this is untested (I'm too lazy to create the files), but i have added some comments to help explain it <?php /*solution06.html <B>[ACCT]<B>: [bAL]<BR /> */ /*solution06.txt 01234567,£12.00 01212367,£1.00 01787787,£57.00 017894567,£102.00 */ $HTML = ""; //OUTPUT html $HTMLPart = file_get_contents('solution06.html'); //get HTML part, just get the whole file into a string $accounts = file('solution06.txt'); // get Details, we use FILE as it reads line by line foreach($accounts as $acc){ //loop though details (line by line) // //Option 1 $details = explode(",",$acc); //convert a comma delimited string into an array $account = $acc[0]; //assign $account to the FIRST item in the array (which is 0) arrays start at 0 $balance = $acc[1]; //assign $balance to the SECOND item in the array //~~OR~~ //Option 2 list($account,$balance) = explode(",",$acc); //convert a comma delimited string into an array and assign variables // $display = str_replace("[ACC]", $account, $HTMLPart); // assign temp html string to html part replacing ACC with account number $display = str_replace("[bAL]", $balance, $display); // assign temp html string to itself replacing BAL with balance $HTML .= $display; // concatanate OUTPUT HTML with updated HTML Part } echo $HTML; //Output PS I'm not in the habit of doing others homework as it will cause more problems for them.. so please make sure it makes sense and any questions please fell free to ask
  6. if you like i can type up the solution and you could test it and reverse engineer it..
  7. Okay, this may help or confuse you more! but if you can point out where you are in what book or explain the exact problem i maybe able to help more okay so create a text file, ie 01234567,£12.00 and a html file ie <B>[ACCT]<B>: [bAL]<BR /> Now So you need to:~ 1. read in the solution06.txt file (hint: file), 2. extract the Account and Balance from the comma delimited lines (hint: explode + bonus hint list) 3. assign the first part to $account and the second part to $balance (hint: $account = array[0] or see bonus hint above) 4. read in the file solution06.html (hint: file_get_contents) 5. use str_replace to replace ACCT and BAL with the $account and $balance 6. echo results / updated string CHECK POINT test what you have.. NOW.. UPDATE, solution06.txt to 01234567,£12.00 01212367,£1.00 01787787,£57.00 017894567,£102.00 new hints (re-read above list but with these hints) 1.5 foreach loop with take you thought each line. 5.5 you may want to use str_replace in a COPY of the solution06.html string) 6.5 concatenate string of multiple solution06.html stings ie $str = file_get_contents('solution06.html'); $display = ""; $display .= str_replace("[ACC]", $account, $str); $display .= str_replace("[bAL]", $balance, $display);
  8. try this $HTML = "test http:\\www.domain.comj\blar.html ing http:\\www.domain.com\test\blar.jpg http:\\www.domain.com\test\blar.html http:\\www.domain.com\blar.html http:\\www.domain.com\blar.gif http:\\www.domain.com\blar.php http:\\www.domain.com\blar.png http:\\www.domain.com\blar.html http:\\www.domain.com\blar.jpg"; $HTML = preg_replace('/\bhttp:\\\\\S+?\\\\[^.]*\.(jpg|png|gif)\S*\b/i', '', $HTML ); echo $HTML;
  9. can you give some examples please. I assume http:\\www.domain.com\blar.html < - replaced with ? http:\\www.domain.com\blar.jpg < - NOT replaced
  10. if Male only contains 1 entry then you could do this if ((current($array['Person']['Male']) == "Bobby"){ // do something } if not you could use a foreach loop
  11. You say the XML is being set from AJAX, so the $xmldoc would be set from request that ajax is sending. (ie $_GET['ajax_request'])
  12. Okay, at the very start of the checkout.php have <?php session_start(); ?> then on the part of the check out that does the redirect, do this $_SESSION['checkedout'] = true; header("Location: thankyou.php"); //the re-direct now in thankyou.php do this <?php session_start(); if(empty($_SESSION['checkedout'])){ header("Location: error.php"); //redirect to error page exit(); } unset($_SESSION['checkedout']); //clear session echo "Thank you"; ?> To summarise: thankyou.php will redirect to an error.php if a session called 'checkedout' is not set or not set to true, and the checkout.php is the only place where it can be set to true.. thus it must be a valid checked out item hope that helps EDIT: oops a typo in the code (fixed)
  13. Okay then 2 questions before I can help.. 1. why have www.site.com/x.php in the public domain ? 2. what is it and why do you have it if you don't want it viewable ?
  14. NO, if that was the case MySpace would of sued FaceBook, did hover sue dyson ? etc a social network is a social network network, Has PHPfreaks been sued by other forums for have a forum ?
  15. Not exactly, $otherreplace is a variable so $otherreplace="16"; $string=preg_replace($otherreplace,$firstreplace,$string,1); is was exactly the same as it you typed $string=preg_replace("16",$firstreplace,$string,1); ie if $tax = 1.75; then 10 + $tax = 11.75 in other words its evaluating to this 10 + 1.75 = 11.75 make sense ?
  16. Basically you need the start and end delimiters, in my example I used / now in preg you MUST the first character becomes the delimiter, and the RegEx ends when it meets another one, any thing after the end delimiter must be a switch, in my example I used i which means case insensitive. as for the quotes, anything inside double quotes is parsed by PHP for example (pay attention to the text formatting / colour) blue being a variable and red a string, your notice one of the $test is red, thus its a string! $test = "testing"; echo $test; //this will return -> testing //also echo "$test"; //this will return -> testing //and echo "$test 123"; //this will return -> testing 123 //however echo '$test 123'; //this will return -> $test 123 //you could also concatenate (using a . ) echo $test.' 123'; //this will return -> testing 123 //So how to quote ? //Well you could either escape or quote //single quotes echo $test.' "123" '; //this will return -> testing "123" //escape echo "$test \"123\" "; //I added a space to make it clearer : returns -> testing "123" Now with all that info I could of created the RegEx like this $string=preg_replace("/".$otherreplace."/i",$firstreplace,$string,1); Hope that helps
  17. True my signature is proof of things posted that could be taken in the wrong context!
  18. Lets just say i know my fair share about how VNC's work, and I take offence to that statement as thats verrrrry basic computer studies stuff, and i feel your attempting to insult my intelligence Really well bend me over and call me carol.. neither of these where the cause of the issule at hand, after reviewing my logs it seams that my work PC tried to make a connection to my Home PC that it well didn't agree with and my FW went nuts, it seams to be an thunder in a tea pot, too many things happened at once!
  19. Well that depends on the which VNC client I was using..! I have reset to Aero and everything is well. when I am next in the office i'll test again..(its no biggie)
  20. <?php $string="one two three four five four three two one"; $search="two"; $firstreplace=2; $otherreplace=16; $string=str_replace($search,$otherreplace,$string); $string=preg_replace("/$otherreplace/i",$firstreplace,$string,1); echo $string; However this is neater/easier to read <?php $string="one two three four five four three two one"; $search="two"; $firstreplace=2; $otherreplace=16; $string=preg_replace("/$search/i",$firstreplace,$string,1); $string=preg_replace("/$search/i",$otherreplace,$string,1); echo $string;
  21. have to confirmed that by eching the path ?
  22. What exactly are you trying to do ? you could use inarray,array_search, even a loop or even serialize both arrays.. but without more detail its hard to make a useful suggection
  23. My test doesn't have SSL installed so i can't publish it their (until i setup openssl on it) I have created a quick video (MP4/quicktime) to show how it should look, [attachment deleted by admin]
  24. Sorry for the delay, I got called way, I had some issules with the cURL route so, I created a trimmed down version of the Zend Framework route, your need to get Zend GData, but other than that this should work, i have tested it locally <?php /* 1 .Get Zend GData from here http://framework.zend.com/download/gdata * 2. open zip and move the Zend folder from the libary to the same folder as this script * 3. update the line at the bottom * $gDoc = new gSpreadSheet('GOOGLE ACCOUNT -EMAIL ', 'PASSWORD'); */ class gSpreadSheet{ private $gdClient; private $currKey; private $Cells; function __construct($username, $password){ //GData setup require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Http_Client'); Zend_Loader::loadClass('Zend_Gdata'); Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); Zend_Loader::loadClass('Zend_Gdata_Spreadsheets'); //Login //Single-user "installed" client authentication (via HTTP) $authService = Zend_Gdata_Spreadsheets::AUTH_SERVICE_NAME; $httpClient = Zend_Gdata_ClientLogin::getHttpClient($username, $password, $authService); $this->gdClient = new Zend_Gdata_Spreadsheets($httpClient); } public function ShowWorkSheets(){ $feed = $this->gdClient->getSpreadsheetFeed(); return $this->printSS($feed); } public function printSS($feed){ foreach($feed->entries as $K => $entry) { if (!$entry instanceof Zend_Gdata_Spreadsheets_CellEntry && !$entry instanceof Zend_Gdata_Spreadsheets_ListEntry ) { print "<p><a href=\"?WS=$K\">{$entry->title->text}</a></p>\n"; } } } public function getCells($feed){ foreach($feed->entries as $entry) { if ($entry instanceof Zend_Gdata_Spreadsheets_CellEntry) { $this->Cells[$entry->title->text] = $entry->content->text; } } } public function getSpreadFeed($id){ $feed = $this->gdClient->getSpreadsheetFeed(); $currKey = split('/', $feed->entries[$id]->id->text); $this->currKey = $currKey[5]; return $feed->entries[$id]->id->text; } public function setWorkSheet($id){ $this->currWkshtId = $id; } public function getCell($cell){ $cell = strtoupper($cell); $query = new Zend_Gdata_Spreadsheets_CellQuery(); $query->setSpreadsheetKey($this->currKey); $query->setWorksheetId($this->currWkshtId); $feed = $this->gdClient->getCellFeed($query); $this->getCells($feed); return $this->Cells[$cell]; } public function getAllCell(){ $query = new Zend_Gdata_Spreadsheets_CellQuery(); $query->setSpreadsheetKey($this->currKey); $query->setWorksheetId($this->currWkshtId); $feed = $this->gdClient->getCellFeed($query); $this->getCells($feed); return $this->Cells; } } $gDoc = new gSpreadSheet('GOOGLE ACCOUNT -EMAIL ', 'PASSWORD'); if(!isset($_GET['WS'])){ $gDoc->ShowWorkSheets(); exit; }else{ $gDoc->getSpreadFeed($_GET['WS']); $gDoc->setWorkSheet(1); var_dump($gDoc->getCell('A2')); echo "<HR />"; var_dump($gDoc->getAllCell()); } ?>
×
×
  • 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.