Jump to content

David-fethiye

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

David-fethiye's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for this, It looks very interesting and I am going to give it try I'll let you know how I get on !
  2. Hi, I want to format my emails to about 70 characters wide and wrap them so that words don't get cut up. Normally php wordwrap() would do the job, but unfortunately this function has a tendency of breaking up html tags and as I have hyperlinks in my emails, I want them to remain intact. In the php manual under wordwrap I found a function called htmlwrap() which states that it does NOT add a "<br>" to the end of 70 character line and force a line wrap. ( this script safely wraps long words without destroying html tags which wordwrap has a tendency of doing - but it does not wrap the text at a certain width) What I want to do is add that line break so that it DOES force a line wrap - but I am not sure where to insert it in the function Can anyone suggest which line of the following function to change ? /* htmlwrap() is a function which wraps HTML by breaking long words and * preventing them from damaging your layout. This function will NOT * insert <br /> tags every "width" characters as in the PHP wordwrap() * function. */ function htmlwrap($str, $width = 70, $break = "\n", $nobreak = "") { // Split HTML content into an array delimited by < and > // The flags save the delimeters and remove empty variables $content = preg_split("/([<>])/", $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); // Transform protected element lists into arrays $nobreak = explode(" ", strtolower($nobreak)); // Variable setup $intag = false; $innbk = array(); $drain = ""; // List of characters it is "safe" to insert line-breaks at // It is not necessary to add < and > as they are automatically implied $lbrks = "/?!%)-}]\\\"':;&"; // Is $str a UTF8 string? $utf8 = (preg_match("/^([\x09\x0A\x0D\x20-\x7E]|[\xC2-\xDF][\x80-\xBF]|\xE0[\xA0-\xBF][\x80-\xBF]|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}|\xED[\x80-\x9F][\x80-\xBF]|\xF0[\x90-\xBF][\x80-\xBF]{2}|[\xF1-\xF3][\x80-\xBF]{3}|\xF4[\x80-\x8F][\x80-\xBF]{2})*$/", $str)) ? "u" : ""; while (list(, $value) = each($content)) { switch ($value) { // If a < is encountered, set the "in-tag" flag case "<": $intag = true; break; // If a > is encountered, remove the flag case ">": $intag = false; break; default: // If we are currently within a tag... if ($intag) { // Create a lowercase copy of this tag's contents $lvalue = strtolower($value); // If the first character is not a / then this is an opening tag if ($lvalue{0} != "/") { // Collect the tag name preg_match("/^(\w*?)(\s|$)/", $lvalue, $t); // If this is a protected element, activate the associated protection flag if (in_array($t[1], $nobreak)) array_unshift($innbk, $t[1]); // Otherwise this is a closing tag } else { // If this is a closing tag for a protected element, unset the flag if (in_array(substr($lvalue, 1), $nobreak)) { reset($innbk); while (list($key, $tag) = each($innbk)) { if (substr($lvalue, 1) == $tag) { unset($innbk[$key]); break; } } $innbk = array_values($innbk); } } // Else if we're outside any tags... } else if ($value) { // If unprotected... if (!count($innbk)) { // Use the ACK (006) ASCII symbol to replace all HTML entities temporarily $value = str_replace("\x06", "", $value); preg_match_all("/&([a-z\d]{2,7}|#\d{2,5});/i", $value, $ents); $value = preg_replace("/&([a-z\d]{2,7}|#\d{2,5});/i", "\x06", $value); // Enter the line-break loop do { $store = $value; // Find the first stretch of characters over the $width limit if (preg_match("/^(.*?\s)?([^\s]{".$width."})(?!(".preg_quote($break, "/")."|\s))(.*)$/s{$utf8}", $value, $match)) { if (strlen($match[2])) { // Determine the last "safe line-break" character within this match for ($x = 0, $ledge = 0; $x < strlen($lbrks); $x++) $ledge = max($ledge, strrpos($match[2], $lbrks{$x})); if (!$ledge) $ledge = strlen($match[2]) - 1; // Insert the modified string $value = $match[1].substr($match[2], 0, $ledge + 1).$break.substr($match[2], $ledge + 1).$match[4]; } } // Loop while overlimit strings are still being found } while ($store != $value); // Put captured HTML entities back into the string foreach ($ents[0] as $ent) $value = preg_replace("/\x06/", $ent, $value, 1); } } } // Send the modified segment down the drain $drain .= $value; } // Return contents of the drain return $drain; } ?> Just to summarize: I would be quite happy to use php wordwrap() to make the line width 70 characters (or as near as possible) if it was not for the fact that it damages the html tags. Also I would be quite happy to use the htmlwrap() if it was not for the fact that it does not wrap ( !! ) at the width. So I wanted an combination of the two, a function that will wordwrap and a given character number ( or as near as it can get with out breaking a word ) and with the protection of the html tags. Can this code - htmlwrap() be converted to wordwarp as well ? Any help much appreciated
  3. Hey, Whad up world. I have a captcha script which should pick up a background image and add some random letters to it and re-display This is the part of the form that the captcha image is part of: <span >Verification Image:</span> <span ><img src="captcha.php" id="captcha" /> <a href="#renew" onclick="javascript: document.getElementById('captcha').src = 'captcha.php?' + Math.random();">refresh</a> </span> <span >Enter 8 character key:</span> <span ><input type="text" name="imgver" id="imgver" onkeyup ="this.value=this.value.toUpperCase()"></span> <input class="button2" type="submit" value="Give Me Free Entry Now"/> And here is the captcha script that is called: #since we are storing our data using Sessions, we need to start a session session_start(); #$bg_image is the image that will be used for the background of our captcha #you will have to replace the value with your bg image. $bg_image = "images/cap02.png"; #we're going to put some lines throughout the image to make it a bit harder for bots to crack #to color the lines, we need to fill in the color fields using RGB values (0-255 for each color) $line_color = array( "R" => 150, "G" => 150, "B" => 150 ); #set the number of line to display in our captcha $numLines = 5; #set the length of the key to display in our captcha $keyLength = 6; #set the color of the text in our captcha $textcolor = array( "R" => 0, "G" => 255, "B" => 0 ); #get some file attribures of our bg image, all we are going to use is witdth and height. list($width, $height, $type, $attr) = getimagesize($bg_image); #using PHP's GD Library, we're going to create our base captcha, which starts with our BG image. $captcha = imagecreatefrompng($bg_image); #sets the color for our key, the color was defined above. $keycol = imagecolorallocate($captcha, $textcolor["R"],$textcolor["G"],$textcolor["B"]); #start a loop to add our lines to our captcha for($i = 0; $i < $numLines; $i++) { $line = imagecolorallocate($captcha,$line_color["R"],$line_color["G"],$line_color["B"]); imageline($captcha,rand(0, $width),rand(0,$height),rand(0, $width),rand(0,$height),$line); } #generate our random key $string = GenKey($keyLength); #add our random key to our captcha imagestring($captcha, 9, rand(1, 30), rand(1, 15), $string, $keycol); #encrypt our key and add it to our session data. $_SESSION['key'] = md5($string); #send HTTP header to tell client we're going to display an image. header("Content-type: image/png"); #dsplay image imagepng($captcha); function GenKey ($length) { #define the letter / number that will be used in our key. $chars = "123456789ABCDEFGHIJKLMNPQRSTUVWXYZ"; #start a loop to make the key. for($i = 0; $i < $length; $i++) { #pick a random start place in the string $rand_start = rand(1, strlen($chars) - 1); #add this character to our key $key .= substr($chars, $rand_start, 1); } #return our key return $key; } ?> I have a background image that is here As far as I can see, everything should work but I get nothing displayed at all. Can anyone spot my errors ?
  4. This must be a common problem - or maybe I am doing it wrong. When I use create a record using a textarea in a form and insert it into my table the returns are invisable. Eg: --------------------- Peter looking for a low-cost, yet highly effective means of advertising your products and services, then Google AdWords may be your answer. Google AdWords provides a simple way to purchase highly targeted advertising , regardless of your budget. Unlike other sites selling banner ad space and pay-per-ranking, AdWords provides advertisers with highly effective text ads that are displayed with the search results. Studies have shown that highly targeted keyword advertising produces an average of four times the industry standard clickthrough rate. Google, one of the premier Search Engines, receives over 29 million searches each day. --------------------- When I veiw the database record they are also invisable yet the formatting stays the same so they are there (some how). I then come to edit/modify the record an if the modifcation contains an error (like the heading is missing) and the record needs to be re-displayed, then I get this kind of display: --------------------- Peter looking for a low-cost, yet highly effective means of advertising your products and services, then Google AdWords may be your answer.\r\n\r\nGoogle AdWords provides a simple way to purchase highly targeted advertising , regardless of your budget. Unlike other sites selling banner ad space and pay-per-ranking, AdWords provides advertisers with highly effective text ads that are displayed with the search results. Studies have shown that highly targeted keyword advertising produces an average of four times the industry standard clickthrough rate.\r\n\r\nGoogle, one of the premier Search Engines, receives over 29 million searches each day. --------------------- If I save this version then the "\r\n\r\n" get recorded as well - ie they are not invisable any more. How can I stop these \r\n\r\n's from showing up ? It seems odd that they don't show up in a straight forward edit - only when there is a mistake and a re-display occurs. This is my safe_sql function: // Make variable SQL safe function safe_sql( $value ) { $value = strip_tags(trim($value)); // Stripslashes if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // Quote if not integer if (!is_numeric($value)) { $value = mysql_real_escape_string($value); } return $value; } // End of Function And here is my form process: if(isset($_POST['tutedit'])) { $N_art_head = safe_sql($_POST['x_art_head']); $N_art_body = safe_sql($_POST['x_art_body']); /* * Check for blanks. */ if ( $N_art_head == "" || $N_art_head == " "){ $err_mes = "The article title appears to be missing!"; require_once ("write_tute_fm.php"); exit(); } // endif if ( $N_art_body == "" || $N_art_body == " "){ $err_mes = "The entire article body is missing!"; require_once ("edit_tute_fm.php"); exit(); } // endif And the form is here: <div class="art_title"> <label for="x_art_head">Title: </label> <input class="data1" type="text" name="x_art_head" size="40" value = "<?php echo $N_art_head ?>" > <span style ="color : red; " > <?php echo "$err_mes"; ?></span> </div> <div class="art_title"> <label for="x_art_body">Content: </label> <textarea class="data1" rows="24" cols="80" name="x_art_body" > <?php echo $N_art_body ?></textarea> </div> I am not sure if I should replace the \r\n with <br> for the re-display or will that make things worse ? I have now tried added nl2br($N_art_body); just before the re-display and Now it shows up with the HTML in it, like this: ----------------- Peter looking for a low-cost, yet highly effective means of advertising your products and services, then Google AdWords may be your answer.<br /> <br /> Google AdWords provides a simp ------------------ I don't think thats what I wanted - I just wanted the formatting to stay in place Since I am using the $value = strip_tags(trim($value)); when taking the POST data I don't think I need to use htmlspecialchars as there shouldn't be any tags left - but maybe I should do that as well just before the db save ?? Any ideas on solving this problem greatly appreciated
  5. Yes - thats it ! I have been reading about concat() but couldn't see how to use it ! So UPDATE tbl SET fld = CONCAT(fld, 'new text'); should do the business Thanks
  6. Hello, I am writing a simple "mini-blog" for my website. I don't want all the works of a wordpress or other program so I am just using a text area to update one of the fields in my table. Is there a way to simply add extra data on the end of a mysql table record without reading the exiesting data into a variable, appending the new info and then UPDATE'ing the record ? Thanks for any info
  7. Hi all ! I am writinga simple image uploading script and want to display the image that is uploaded - preferably BEFORE it is sent by means of js. BUT i also have encountered a silly problem ! First I can't get over this simple problem !! My server is set up as localhost on :d/web/ in the following HTML file all the images show - as you'd expect ! <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> </head> <body> <img src="file:///D:/Web/fethiye/turkey.gif" border="2"> <img src="http://localhost/fethiye/images/town.jpg" border="2"> <img src="http://localhost/fethiye/turkey.gif" border="2"> <img src="file:///D:/Web/fethiye/turkey.gif" border="2"> </body> </html> BUT in my PHP file i get a problem - only the images with the [a href=\"http://localhost\" target=\"_blank\"]http://localhost[/a] path are displayed the others with the file:/// path are broken ??? Any one know why this is ? HERE is the php code UPLOAD.PHP calls UPLOAD_FORM.INC PHP Code: <?php /* upload.php * CALLS upload_form.inc */ if (!isset($_POST[upload])) { $message1 = "Enter File Path"; $message2 = " Now "; include ("upload_form.inc"); } // endif else { if($_FILES['pix']['tmp_name'] == "none") { $message1 = "File did not successfully upload."; $message2 = "Check the file size. Must be less than 250K"; include ("upload_form.inc"); exit(); } // endif if(!ereg("image",$_FILES['pix']['type'])) { $message1 = "File is not a picture file."; $message2 = "Please try a different file."; include ("upload_form.inc"); exit(); } // endif else { $destination = 'd:\web\data'."\\".$_FILES['pix']['name']; $temp_file = $_FILES['pix']['tmp_name']; move_uploaded_file($temp_file,$destination); $message1 = "File has been successfully uploaded."; $message2 = "CONGRATULATIONS !"; include ("upload_form.inc"); exit(); } // end else } // end else ?> ------------------------------------------ and now the form : PHP Code: <?php /* upload_form.inc * CALLED BY upload.php (and recalls it). */ ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <!-- Upload_form.inc Description : displays the a form for uploading data --> <html> <head> <title>Untitled</title> <script language="JavaScript" type="text/javascript"> <!-- function changeSrc1(who){ img=who.replace(who.substring(0,1),'file:///'+who.substring(0,1));//add 'file:///' before the drive letter img=img.replace(/\\/g,'/');//replace all backslashes with forward slashes document.getElementById('preView1').src=img; } // end of function --> </script> </head> <body> <img src="file:///D:/Web/fethiye/turkey.gif" border="2"> <img src="http://localhost/fethiye/images/town.jpg" border="2"> <img src="http://localhost/fethiye/turkey.gif" border="2"> <img src="file:///D:/Web/fethiye/turkey.gif" border="2"> <div style='position:absolute; left:20px; top:60px'> <form enctype ="multipart/form-data" action="upload.php" method="POST"> <input type="hidden" name ="MAX FILE SIZE" value="500000"> <table width="400px" border="0" cellspacing="0" cellpadding="1"> <tr> <td>Picture file path: </td> <td> <input type="file" id="x_pix1" size="50" onchange="changeSrc1(this.value)" name="pix" value = "<?php echo $x_pix1 ?>"> </td></tr> <tr><td> <input type="submit" name="upload" value="Upload Picture"> </td></tr> </table> </form> </div> <div id='PreView1' style='position:absolute; left:30px; top:200px' > <img id="preView1" width="120" height="120" /> <br> - - - Picture 1 - - - </div> <div style='position:absolute; left:200px; top:300px'> <?php echo $message1 ?><br> <?php echo $message2 ?><br> </div> </body> </html> --------------------------------------------------- BTW the js script is not working yet - but thats another problem ! Please help if you can !
  8. After extracting the php5 files into my php directory ı need to modify the httpd.conf file Trouble is these instruction (below) are for php4 can someone please tell me what i should replace them with for php5 ? I have tried various guesses but Apache failed to start. (instructions) Modifying Apache Configuration Apache doesn't know that you just install PHP. We need to tell Apache about PHP and where to find it. Open the Apache configuration file in C:\Program Files\Apache Group\Apache2\conf\httpd.conf and add the following three lines : LoadModule php4_module php/sapi/php4apache2.dll AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps ( end instructions) Thanks.
  9. In order to install Apache2 and php5 and mysql5 is it best use something like XAMPP or WAMP ? Also is it better to go for the new Apache2 rather the version 1.3 ? Same goes for php5 vs 4 and mysql5 Are the '5' s stable and faily bug-free I want to get on with the installation so your suggestions are much appreciated :) David
×
×
  • 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.