Jump to content

Nodral

Members
  • Posts

    397
  • Joined

  • Last visited

Everything posted by Nodral

  1. Delimiters? Sorry, not really used regex before, finding it's a whole different ball game!!!
  2. Ok, done that and it removes all characters. I think i'm getting a certain amount of 'garbage' in my strings, due to them being imported from a tab seperated csv file. Any thoughts how I can 'clean' the input, or check it is set to the correct encoding?
  3. Hi I need to strip all non alphanumeric characters from a string except an underscore. Here's what I have so far which works from the non alphanumeric bit, how do I then ignore underscores? $value = ereg_replace("[^A-Za-z0-9]", "", $value ); Any help would be greatly appreciated.
  4. As we're into the 'Green' era of recycling, I've used this code on practically every site I've worked on to display my HTML <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE><?php echo $title; ?></TITLE> <META NAME="Generator" CONTENT="*******"> <META NAME="Author" CONTENT="**********"> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> <?php echo $redirect; ?> <script type="text/javascript" src="myScripts.js"></script> <!-- a few page styles--> <link rel="mystyles.css" type = css/text> </HEAD> <BODY> <div id="wrapper"> <div id="banner"> <?php echo $banner; ?> </div> < <div id="content"> <?php echo $output; ?> </div> </div> </BODY> </HTML> As you can see, I can simply do my processing and then include this file with all / some of the variables set. I've got another couple I include if I need a 2 column or 3 column display
  5. Absolutely Brilliant!!!!!!!! Don't really understand what you did, but it works!!!!!!!!!! One further question. How would I attach more than one file?
  6. I personally find it better to have all my HTML in a seperate file. Then create variables loaded with the dynamic content and include the output file. eg //HTML PAGE called output.php <body> <div> <h1> <!--etc etc --> <?php echo $output; ?> </h1> </div> </body> //php $output ="Hello World"; include("output.php") Everything is much tidier, and if you're clever about it you can use the same output.php page for practically everything. I would then have a seperate file for CSS and anothe rfor Javascript which would also be called by the output.php
  7. function emailJI($to, $subject, $attachment, $content){ /* Email Detials */ $mail_to = "$to"; $from_mail = "Admin@********.co.uk"; $from_name = "*******Administrator"; $reply_to = "******.******@******.com"; $subject = "$subject"; $message = "$content"; /* Attachment File */ // Attachment location $file_name = "prebrief.pdf"; $path = ""; // Read the file content $file = $path.$file_name; $file_size = filesize($file); $handle = fopen($file, "r"); $att = fread($handle, $file_size); fclose($handle); $att = chunk_split(base64_encode($att)); /* Set the email header */ // Generate a boundary $boundary = md5(uniqid(time())); // Email header $header = "From: ".$from_name." <".$from_mail.">\n"; $header .= "Reply-To: ".$reply_to."\n"; $header .= "MIME-Version: 1.0\n"; // Multipart wraps the Email Content and Attachment $header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n"; $header .= "This is a multi-part message in MIME format.\n"; $header .= "--".$boundary."\n"; // Email content // Content-type can be text/plain or text/html $header .= "Content-type:text/html; charset=iso-8859-1\n"; $header .= "Content-Transfer-Encoding: 7bit\n"; $header .= "$message\n"; $header .= "--".$boundary."\n"; // Attachment // Edit content type for different file extensions $header .= "Content-Type: text/pdf;"; $header .="name=\"prebrief.pdf\"\n"; $header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n"; $header .= "Content-Transfer-Encoding:base64\r\n"; //$att= "<html><head><title></title></head><body>Test attachment for mail delivery</body></html>"; $header .= $att."\n\n"; $header .= "--".$boundary."--"; // Send email if (mail($mail_to, $subject, "", $header)) { echo "Sent"; } else { echo "Error"; } }
  8. That all depends where $temp is set and what it contains. Without someone reading every line of your code it's gonna be pretty impossible to say what will be affected where.
  9. This still not working. If I remove the encoding then the HTML we tested with comes through fine, but if I use pdf then it says encoding is wrong. Please Please Please someone help with this, I can't fathom it at all.
  10. ok, corrected that, But using the HTML as muddy suggested outputs
  11. Ok, I've changed the file to HTML as suggested, and I just get a load of Gobble-de-gook symbols. Hmmmmmm, strangerer and strangerer. any more ideas guys?
  12. $name is what it will be displayed as on the email $path is the actual location of the file on the server
  13. OK, the message comes through nicely as HTML now, however the attachment is still saying it's corrupted and not been decoded correctly /* Attachment File */ // Attachment location $file_name = "prebrief.pdf"; $path = "prebrief.pdf"; // Read the file content $file = $path.$file_name; $file_size = filesize($file); $handle = fopen($file, "r"); $att = fread($handle, $file_size); fclose($handle); $att = chunk_split(base64_encode($att)); /* Set the email header */ // Generate a boundary $boundary = md5(uniqid(time())); // Email header $header = "From: ".$from_name." <".$from_mail.">\n"; $header .= "Reply-To: ".$reply_to."\n"; $header .= "MIME-Version: 1.0\n"; // Multipart wraps the Email Content and Attachment $header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n"; $header .= "This is a multi-part message in MIME format.\n"; $header .= "--".$boundary."\n"; // Email content // Content-type can be text/plain or text/html $header .= "Content-type:text/html; charset=iso-8859-1\n"; $header .= "Content-Transfer-Encoding: 7bit\n"; $header .= "$message\n"; $header .= "--".$boundary."\n"; // Attachment // Edit content type for different file extensions $header .= "Content-Type: application/pdf; name=\"".$file_name."\"\n"; //$header .= "Content-Transfer-Encoding: base64\n"; $header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\n"; $header .= $att."\n"; $header .= "--".$boundary."--"; // Send email if (mail($mail_to, $subject, "", $header)) { echo "Sent"; } else { echo "Error"; }
  14. Ok, attachment coming through now, but it is saying it cannot be opened as it wasn't encoded properly, and the message is still plain text and not HTML. Here's my amended code /* Attachment File */ // Attachment location $file_name = "prebrief.pdf"; $path = "prebrief.pdf"; // Read the file content $file = $path.$file_name; $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); /* Set the email header */ // Generate a boundary $boundary = md5(uniqid(time())); // Email header $header = "From: ".$from_name." <".$from_mail.">\n"; $header .= "Reply-To: ".$reply_to."\n"; $header .= "MIME-Version: 1.0\n"; // Multipart wraps the Email Content and Attachment $header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n"; $header .= "This is a multi-part message in MIME format.\n"; $header .= "--".$boundary."\r\n"; // Email content // Content-type can be text/plain or text/html //$header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\n"; $header .= "$message\n"; $header .= "--".$boundary."\n"; // Attachment // Edit content type for different file extensions $header .= "Content-Type: application/pdf; name=\"".$file_name."\"\n"; $header .= "Content-Transfer-Encoding: base64\n"; $header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\n"; $header .= $content."\n"; $header .= "--".$boundary."--"; // Send email if (mail($mail_to, $subject, "", $header)) { echo "Sent"; } else { echo "Error"; } }
  15. Hi All I'm trying to send an email with an attachment, but all I get is the content and the MIME headers coming through as plain text in the body. It needs to be HTML with a pdf attachment. Any thoughts what I'm doing wrong. My knowledge of MIME headers etc is as limited as cutting and pasting this code from Google, and amending it to try to do what I need. function emailJI($to, $subject, $attachment, $content){ /* Email Detials */ $mail_to = "$to"; $from_mail = "Admin@*****.co.uk"; $from_name = "***** Administrator"; $reply_to = "*****.*****@*****.com"; $subject = "$subject"; $message = "$content"; /* Attachment File */ // Attachment location $file_name = "prebrief.pdf"; $path = "prebrief.pdf"; // Read the file content $file = $path.$file_name; $file_size = filesize($file); $handle = fopen($file, "r"); $content = fread($handle, $file_size); fclose($handle); $content = chunk_split(base64_encode($content)); /* Set the email header */ // Generate a boundary $boundary = md5(uniqid(time())); // Email header $header = "From: ".$from_name." <".$from_mail.">\r\n"; $header .= "Reply-To: ".$reply_to."\r\n"; $header .= "MIME-Version: 1.0\r\n"; // Multipart wraps the Email Content and Attachment $header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"\r\n"; $header .= "This is a multi-part message in MIME format.\r\n"; $header .= "--".$boundary."\r\n"; // Email content // Content-type can be text/plain or text/html //$header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= "$message\r\n"; $header .= "--".$boundary."\r\n"; // Attachment // Edit content type for different file extensions $header .= "Content-Type: application/pdf; name=\"".$file_name."\"\r\n"; $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n"; $header .= $content."\r\n"; $header .= "--".$boundary."--"; // Send email if (mail($mail_to, $subject, "", $header)) { echo "Sent"; } else { echo "Error"; } }
  16. ok, you've said that the code is updating all the fields in your database, but have not given the code which could feasibly do this. It will be in your script as "UPDATE ****............................WHERE................" Also, if you wrap your code in tags which are @[@code@] "code here" [@/code@]@ (remove the @ signs). Once you've got the tags in place, put linebreaks in to make it easier to read, you may even spot a few errors youself. eg <input type="text" id="uuser_address" name="uuser_address" value="<?php echo("$slide[address]"); ?>"> <br /> <input type="text" id="uuser_town" name="uuser_town" value="<?php echo("$slide[town]"); ?>"> <br /> <input type="text" id="uuser_county" name="uuser_county" value="<?php echo("$slide[county]"); ?>"> <br /> <input type="text" id="uuser_postcode" name="uuser_postcode" value="<?php echo("$slide[postcode]"); ?>"> </div> (wasn't that much more of a please to read!! lol)
  17. Without seeing your sql code, this is fairly impossible to explain. Can you also use code tags, tabs and newlines for your code, at least then we get half a chance at seeing what's going on.
  18. There's load of great articles and tutorials about form validation out there. Try Googling it!!!
  19. Or use a bit of Javascript to disable the back button.
  20. Hi I'm creating a control panel which allows the user to input some text and then play around with the colours and fonts whilst seeing it in a preview panel. My Javascript is not that strong and I'm struggling to get the input color. CSS #colour1{ background-color:red; } HTML controls <td class="colours"><button id="colour1" onClick="changeColor('colour1');"></button></td> <td rowspan="4" width="60%"><span id="preview" >Hello World</span></td> js Function function changeColor(input){ var element =document.getElementById(input); var elementColor = document.getElementById(input).style.backgroundColor; document.getElementById('preview').style.color=document.getElementById(input).style.backgroundColor; } This does absolutely nothing, how can I make it work?
  21. Hi I have a script which references a DB and then produces an XML output saved as XLS to then open in Excel. This works an absolute dream in my dev environment using IE7 and in live using Firefox. However my entire audience uses IE7 and this is where it breaks in the live environment. For some reason, I cannot get the download to work. I get a windows pop-up with an error on it - see attached. If you need to see code, let me know which bit of code could possibly cause this, i.e. headers etc. I've not posted code as there's loads of it and I can't understand why it works in dev in IE 7 but not in live, and works in Firefox in live.
  22. Hi All I've little Javascript kowledge so I'm hoping that some people here will be able to help me. I have a form which contains 37 checkboxes. Of these, 10 have a class of 'time' and I need one checkbox to tick/untick all 10 of them. I have the following code, but it doesn't work and I get an error of Here is my function function checkAll(theForm, cName, status) { for (i=0,n=theForm.elements.length;i<n;i++) if (theForm.elements[i].className.indexOf(cName) !=-1) { theForm.elements[i].checked = status; } } and then the checkboxes are dynamically created with data from a DB as follows. <input type='checkbox' class='time' Name='$i' value='$key'>$value</br> The checkboxes appear correctly in the HTML and with the correct class displayed. Any thoughts? The checkbox must NOT tick every box on the screen, just the ones with a class of "time"
  23. Hi I've written a function which should reference a couple of arrays, and return an array of the length of the longest value in the arrays. Confused, let me explain some more. <?php function getLongest($records,$headers){ foreach ($headers as $fieldid){ foreach($records as $recordid){ $length[]=strlen(getContent($fieldid,$recordid)); } $result[$fieldid]=max($length); } return $result; } ?> I pass in 2 arrays, the first ($records) being references to the record id's from my DB, the second ($headers) is the column from my DB table where I pull the record info from. I have another function getContent which cross references these 2 values and gets the actual data (this works fine) I am trying to create an array of every content entry for each heading, then iterate through it and find the longest value. Then return an array of heading reference against longest content length. My content varies between 10 characters to a couple of hundred characters long, dependant on the column. I have approx 3000 entries in the DB. The results I'm getting are just not what I'd expect, i.e, I run the function against columns showing longtitude and latitude of locations, (expect the result to be approx 12 for the longest) but I get 38?!?! I've even tried using trim() with it incase there's any leading / trailing whitespace. Any thoughts?
  24. To be fair, I do a lot of development in Moodle, and it's a standard feature that an admin can log in as any user.
×
×
  • 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.