therealwesfoster
Members-
Posts
345 -
Joined
-
Last visited
Everything posted by therealwesfoster
-
Sweet, I'll give it a try. Does the ? just mean "be lazy and grab the first one you see"? Wes
-
When I run a preg_match, and there are multiple </b> (where i want the regex to stop), how can I make it stop at the NEXT occurrence? Sometimes it skips all the way to the last occurrence, or somewhere in between. IE: Here's my sample code: <h2> <i> <div> <b> <i id="2">My text!</i> </b> </div> </i> </h2> And my regex: (this is a quick throw-together.. non tested. just to help me ask my question) <?php $string = file_get_contents("THE_ABOVE_CODE"); $body = preg_match('/\<i id="2">(.*)\<\/i>/ism',$string,$match); echo "<pre>".print_r($match)."</pre>"; ?> Now in the code, instead of selecting the </i> right after the text "My Text!", it selects the last </i> in the script... why? Thanks
-
[SOLVED] Simple array question
therealwesfoster replied to therealwesfoster's topic in PHP Coding Help
That'll work man. Much appreciated. And as for the comment, you'll learn in life that some things just aren't worth dwelling on. Thanks again -
[SOLVED] Simple array question
therealwesfoster replied to therealwesfoster's topic in PHP Coding Help
How can I use something like array_push() for associative arrays? And be able to push multiple associative arrays at once (in the same function) -
[SOLVED] Simple array question
therealwesfoster replied to therealwesfoster's topic in PHP Coding Help
Enough with the sarcasm kid. I don't want to go through and have: $template['assign']['VAL3'] = $val3; $template['assign']['VAL4'] = $val4; $template['assign']['VAL5'] = $val5; etc. etc. etc. So how would I re-write the: <?php $template['assign'] = array( "VAL2" => $val2, "VAL3" => $val3 ); ?> etc. In order to push them -
[SOLVED] Simple array question
therealwesfoster replied to therealwesfoster's topic in PHP Coding Help
Thanks for the reply and the weird face. I tried that though, and it doesn't work. What I did: <?php $template['assign']["PIC0"] = $val; $template['assign'] = array( "VAL2" => $val2, ); ?> I think the second declaration is overwriting the first. So how would I re-write the second array push? Wes -
You know how you can do this to add another key to the end of an array? <?php $ar = array(); $ar[] = "First entry"; $ar[] = "Second entry"; ?> Well, how would you do it for an array like below: <?php $ar = array("First" => "1st", "Second" => "2nd"); $ar[] = "Third" => "3rd"; ?> I know the way I did it was completely wrong, but hopefully you get what I'm trying to do. I would look through google for the answer, but I don't know what you would call that. In-line array pushing? lol thanks
-
[SOLVED] Urgent regex help please :)
therealwesfoster replied to therealwesfoster's topic in Regex Help
Thanks for the sarcasm. gosh, what happened to these forums -
[SOLVED] Urgent regex help please :)
therealwesfoster replied to therealwesfoster's topic in Regex Help
Nevermind, i just got it. I added the /s modifier to the end. <?php $file = '<div class="body">my stuff</div>'; echo preg_match('/\<div class="body">(.*)\<\/div>/ism',$file,$match); ?> -
My code: <?php $file = '<div class="body">my stuff</div>'; echo preg_match('/\<div class="body">(.\s*)\<\/div>/im',$file,$match); ?> I'm trying to match what is in between the <div> tags. I know how to match regularly, but there is a newline in-between the <div> tags. I can't figure out how the make it match that. Please help, Thanks
-
Firstly, here's my code: form.php <tr> <td align="center"><input type="text" name="name_{$id}" value="{$name}" /></td> <td align="center"><input type="checkbox" name="showcb[]" value="{$id}" {$checked} /></td> </tr> That is in a MYSQL loop that displays all of the entries from the database (I didn't include all the code because the error isnt in that script). The checkbox allows the user to set if they want that particular entry to be shown on the homepage. The collector: post.php <?php // Get the post vars foreach ($_POST['showcb'] as $key => $val) { // All this is doing is grabbing the post vars $id = $val; $name = (strlen($_POST['name_'.$id]) > 0) ? addslashes($_POST['name_'.$id]) : ""; $show = (isset($key)) ? "1" : "0"; // $sql = "UPDATE table SET t_show='{$show}', t_name='{$name}' WHERE t_id='{$id}'"; // This echo is for debugging echo $sql." [ $key ] [ $val ] [ {$_POST['showcb'][1]} ]<br />"; mysql_query($sql) or die(mysql_error()); } ?> Now, the script works, it updates the name and and "show" of the row. But here is the problem.. it only updates the rows if the checkbox is checked! So in other words, I can't un-check a checkbox because it wont get ran in the foreach() loop. PHP doesn't store the checkbox in the $_POST if it isn't checked.. .so how can i go about doing this? Wes
-
Send POST data without a form
therealwesfoster replied to therealwesfoster's topic in PHP Coding Help
It seems that on process.php, it's just including the receive.php on its page? I might be taking this all wrong.. just thought I'd mention this -
Send POST data without a form
therealwesfoster replied to therealwesfoster's topic in PHP Coding Help
Thanks, I have this now. <?php // Redirect $curl_session = @curl_init('./receive.php'); @curl_setopt($curl_session, CURLOPT_POST, 1); @curl_setopt($curl_session, CURLOPT_POSTFIELDS, "name=$username"); @curl_setopt($curl_session, CURLOPT_FOLLOWLOCATION, 1); $send = @curl_exec($curl_session); if (!send) { // well.. didnt work } ?> The code doesn't redirect properly... Any help? Wes -
Send POST data without a form
therealwesfoster replied to therealwesfoster's topic in PHP Coding Help
Hmm.. seems like it would work. I'll try it in just a sec. More suggestions welcome -
How can I send POST data without using a form? For instance, when process.php loads, I want it to load an entry from the DB, and sent it to receive.php as a POST variable. Maybe it can be done with CURL, but I'm not familiar with that so idk. Suggestions, tips, tutorials.. anything is welcome. Thanks
-
Export MySQL to Excel OR Creating Excel with PHP
therealwesfoster replied to therealwesfoster's topic in PHP Coding Help
Awesome, thanks everyone! Especially you ben. I'll put that to good use Wes -
I have 2 questions. 1. How would I go about exporting my MySQL data into a Microsoft Excel file so the user can download it? For instance, the user goes to /download_db.php. I want the file to run a MySQL query which saves all the information to an excel file and allows the user to download it. 2. How would I use PHP to read and write to an excel file? So every time someone enters their email address in a form, the PHP should open /file.xls, read it, append the new email address to the file, and save it. That way the user could just go to /file.xls and read/download the information. Please help on both questions if you can. I'm only going to be doing 1 of the 2, whichever is quicker. Thanks, Wes
-
[SOLVED] PHP Mail help - Need an experts eye
therealwesfoster replied to therealwesfoster's topic in PHP Coding Help
Well, apparently this line was the problem. $headers = 'MIME-Version: 1.0' . "\r\n"; I wonder why? Wes -
For some reason, when I send emails from the server along with headers, the headers show up in the email like text... why is that? I've done this many times before.. Here's the code: <?php $confirm_email = "THEIR_EMAIL@gmail.com"; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: '.$confirm_email . "\r\n"; $to = "MY_EMAIL@gmail.com"; $message = " <html> <head> <title>Submission</title> </head> <body> Author: ".htmlspecialchars_decode($confirm_author)."<br /> Email: {$confirm_email}<br > </body> </html> "; // Send the confirmation email $mailit = mail($to, "New Article Submission: {$confirm_title}", $message, $headers); ?> It shows up like this (this is all in the body of the email): (the MY_EMAIL and THEIR_EMAIL is, of course, edit by me and not actually in the code). Please help! Wes
-
[SOLVED] Blank page when using array_push HELP
therealwesfoster replied to therealwesfoster's topic in PHP Coding Help
Well, I solved it. It was faulty coding by me with all those parenthesis.. But I wonder why it wasn't showing my errors? -
[SOLVED] Blank page when using array_push HELP
therealwesfoster replied to therealwesfoster's topic in PHP Coding Help
I just realized that I didn't have enough ) on some of my statements. I've fixed that and it still doesn't work. :-\ -
This is kind of urgent, just keep that in mind Whenever I use these 1-line conditional statements, the page doesnt load: The page is completely blank. I have no idea what it could be. But If I remove all the lines like that, the page loads fine. Why is that? And how can I fix this? Here's more code: <?php // Set an error holder $error = array(); //---- // Lets load all of the variables from the form // // Required stuff $author = (strlen($_POST['r_Author'] > 0) ? addslashes($_POST['r_Author']) : array_push($error,"Please enter an Author"); $email = (checkEmailAddress($_POST['re_email']) ? $_POST['re_email'] : array_push($error,"Please enter a valid email address"); $type = (preg_match('/^[a-zA-Z]$/',$_POST['r_Type']) ? $_POST['r_Type'] : array_push($error,"Invalid article type"); $title = (strlen($_POST['r_Title']) > 0) ? $_POST['r_Title'] : array_push($error,"Please enter a title for your article"); $photos = (preg_match('/^[a-zA-Z]$/',$_POST['r_Photos'])) ? $_POST['r_Photos'] : array_push($error,"Invalid choice for photos. Choose Yes or No"); $captcha= (strlen($_POST['captcha']) > 0) ? $_POST['captcha'] : array_push($error,"You didn't enter the captcha code"); $captcha= (md5(sha1($captcha)) == $_SESSION['key']) ? $captcha : array_push($error,"The captcha code you entered is invalid."); $terms = (isset($_POST['Terms_Of_Agreement'])) ? true : array_push($error,"Please agree to the terms of service"); // Non-required $summary = addslashes($_POST['Summary']); $article = addslashes($_POST['Article']); ?> And yes, all the $_POST vars are set. I even set error_reporting(E_ALL) ON.. and nothing shows at all... Remember.. urgent. Thanks