Jump to content
Larry Ullman's Book Forums

Max

Members
  • Content Count

    104
  • Joined

  • Last visited

Community Reputation

2 Neutral

About Max

  • Rank
    Advanced Member
  1. ...and I am killing off any emails in the first category as I don't want to receive them anyway.... $very_bad = array('to:' , 'cc:', 'bcc:', 'content-type:', 'mime-version', 'multipart-mixed', 'content-transfer-encoding:', 'sex', 'bitcoin', 'resource', '$', 'city', 'money', 'traffic', 'GetaBusinessLoan', 'bitcoin', 'ProFunding', 'BusinessLoan', 'einfac'); foreach ($very_bad as $v) { if (stripos($value, $v) !== false) { die(); } } I don't know it that is bad programming practice to kill a program in mid-flow (like the dreaded BASIC GOTO command), but it does work!
  2. I have also changed the criteria so: $very_bad = array('to:' , 'cc:', 'bcc:', 'content-type:', 'mime-version', 'multipart-mixed', 'content-transfer-encoding:', 'sex', 'bitcoin', 'resource', '$', 'city', 'money', 'traffic', 'GetaBusinessLoan', 'bitcoin', 'ProFunding', 'BusinessLoan', 'einfac'); which has cut downthe deluge of spam that I used to get.
  3. Hi there I hope you are well, Larry. I decided to re-visit my 'Contact us' page and review the spamscrubber. I was having trouble getting the spamscrubber to fish out the '\n's and '\r's to the extent that I changed the blank spaces to letters: function spam_scrubber($value) { //Create spam scrubber array.............. $very_bad = array('to:' , 'cc:' , 'bcc:' , 'content-type:' , 'mime-version' , 'multipart-mixed' , 'content-transfer-encoding:'); //For loop comparing email text to bad words....... foreach ($very_bad as $v) { //Look for bad word using stripos to ID the characters in the string. It will return a blank if found...... if (stripos($value, $v) !== false) { return 'AA'; } } $value = str_replace(array( "\r" , "\n" , "%0a" , "%0d"), 'BB' , $value); echo $value; return trim($value); } which made it easier to see what was going on. Thus my enquiry that included some '\n's and '\r's went through the email system WITH the '\n's and '\r's. So I then changed the code to (in red): function spam_scrubber($value) { //Create spam scrubber array.............. $very_bad = array('to:' , 'cc:' , 'bcc:' , 'content-type:' , 'mime-version' , 'multipart-mixed' , 'content-transfer-encoding:'); //For loop comparing email text to bad words....... foreach ($very_bad as $v) { //Look for bad word using stripos to ID the characters in the string. It will return a blank if found...... if (stripos($value, $v) !== false) { return 'AA'; } } $value = str_replace(array( "\\r" , "\\n" , "%0a" , "%0d"), 'BB' , $value); return trim($value); } and it works just fine. Thought I should let you know. Regards Max
  4. OK, have just got it. There is no need to use YEAR() function as the Date column will accept SELECT * FROM Timeline WHERE Date LIKE '%$i%' SORT BY Date ASC All working now. www.gssr.es/timeline.php Adios!
  5. Hi Larry and everyone, I have really painted myself into a corner with this one. Above is the database that I created for a timeline. The issue is that not all of the dates at my disposition have days and months. Some are just years. Hence, I had to make a separate column for years only. What I want to do is create a timeline using tables so that any year that has either a YYYY date and/or a YYYY-MM-DD date appears in chronological order. I tried it with a for loop starting at $i = 1700 - 2000 which works for the first year but the while ($enquiry3 = @mysqli_fetch_array($enquiry2)) { will only iterate once and then stops. The alternative is to use MySQL such as: for($i = 1700; $i <= 2000; i++) { $enquiry = "SELECT * from Timeline WHERE Year = $i ORDER BY Year ASC" } which works OK for getting the year only files. Then we need to get the full date files so we try: for($i = 1700; $i <= 2000; i++) { $enquiry = " SELECT * from Timeline WHERE Date = YEAR($i, %Y) ORDER BY Date ASC" } ....but the date function doesn't seem to work. Any ideas??? Regards Max
  6. Hi all, Well, finally solved it. What really complicated matters was that my browser was converting the (correct) answer from php back to html entities! This led me to believe that php wasn't actually doing anything. So, it has all come down to two lines of code:.... $search = trim($_POST['Search']); $search = htmlentities($search); Now, php can do the MySQL search and now finds matches. To get round the problem on the test script I added as the first line: header('Content-Type: text/plain'); .....so now my test script works as well. Best regards and thank you, Larry. Max
  7. Hi Larry, html : <meta charset="utf-8"> <!--[if lt IE 9]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> MySQL: Collation on all relevant columns and tables are utf-8_unicode_ci When I use phpMyAdmin the accented characters show as ASCII entities (i.e. á = &aacute;), which is what I want. It all works fine: Inauguraci&oacute;n. Bendici&oacute;n de las locomotoras - &Aacute;guilas. Marzo 1890. - from phpMyAdmin becomes..... Inauguración. Bendición de las locomotoras - Águilas. Marzo 1890. The entities in MySQL have been converted to accented text as wanted. The problem seems to be that php isn't recognising the accented characters and thus not converting them to ASCII entities for the search engine that I am trying to create. Thanks as always for your time and help.
  8. I have come across htmlentities and htmlspecialchars but neither seems to work. Here is a Q&D test: <?php if(isset($_POST['char'])) { $char = $_POST['char']; $char2 = htmlentities($char); echo 'Answer: ' . $char . '<br /><br />'; echo $char2; } echo '<form action = "char_test.php" method = "post"> <input type = "text" name = "char" size = "6"> <input type = "submit" name = "submit" value = "Search!" /> </form>'; if I entered á then I would expect the answer to be: Answer: á &aacute; but I get: Answer: á á This goes for all of the characters that I have tried. Surely php wouldn't put something in their manual that doesn't work?
  9. Hi Larry and everyone, I'm still using your book as php is still reducing me to tears. Here is the problem: I have created a large database in English and Spanish. In spite of setting the MySQL db to UTF-8 it still returns nonsense characters with eg accented 'a', so I have been entering all of the text with accents as for example á = &aacute;, Ú = &Uacute;, ñ = &ntilde; as the only way to guarantee that they print correctly when called. The problem is that when a Spaniosh speaker does a search, then they will search for eg 'Estación' not 'Estaci&oacute;n. The php if conditional doesn't recognise accented characters so I need to parse each word letter by letter and convert any accented character to its ASCII decimal to then convert it to the ASCII entity i.e. 'á' => &225; => &aacute; to present to MySQL. I can't find a converter in the turgid php manual so am stuck. I have re-read your chapter 'Making Universal Sites' but have now resorted to coming home to daddy. Thanks Max
  10. The words are fact. I will look at including regular exressions in the glob(). Regards Max
  11. Further to the above comment, I have stumbled across something called 'imagick' which is part of the PHP domain. The PHP manual says something like this: bool Imagick::resizeImage ( int $columns , int $rows , int $filter , float $blur [, bool $bestfit = false ] ) ..and gives examples like this: <?php function resizeImage($imagePath, $width, $height, $filterType, $blur, $bestFit, $cropZoom) { //The blur factor where > 1 is blurry, < 1 is sharp. $imagick = new \Imagick(realpath($imagePath)); $imagick->resizeImage($width, $height, $filterType, $blur, $bestFit); $cropWidth = $imagick->getImageWidth(); $cropHeight = $imagick->getImageHeight(); if ($cropZoom) { $newWidth = $cropWidth / 2; $newHeight = $cropHeight / 2; $imagick->cropimage( $newWidth, $newHeight, ($cropWidth - $newWidth) / 2, ($cropHeight - $newHeight) / 2 ); $imagick->scaleimage( $imagick->getImageWidth() * 4, $imagick->getImageHeight() * 4 ); } header("Content-Type: image/jpg"); echo $imagick->getImageBlob(); } ?> ...which I can't get to work. Larry - perhaps this could be a subject for your next book? Last time I suggested a book, you brought out the excellent (but headache inducing ) Javascript - Develop and Design, which I was pleased to buy but had to read about 5 times for it to start to sink in. Old dogs and new tricks??? I'm sure it would be a good seller. You certainly have a way of explaining very complex subjects.
  12. Another question for Larry. I would like to offer a library of all of the thousands of images that I have in my raw data directory by displaying thumbnails. I know I can use: <a href = "images/raw/yadayada.jpg" target = "_blank"><img style = "width: 100px;" src = "images/raw/yadayada.jpg" .... /> </a> but this will involve huge overheads as it will mean downloading approx 1Mb images and then resizing them in the browser, so I would prefer to resize the images in PHP before downloading them, but I can't find any reference to this in the PHP manual, or the PHP GD manual. Any advice would be much appreciated. Max
  13. Just spotted a problem with the script - it is only checking files with the extension .jpg, not .JPG. Have changed: //Now create a variable ($getlisting) to be able to call only the category that we are interested in... $getlisting = 'images/' . $category . '/*.jpg'; to: //Now create a variable ($getlisting) to be able to call only the category that we are interested in... $getlisting = 'images/' . $category . '/*.*'; - can't really see any neat way around it. I suppose I could run it twice, once with .jpg and then with .JPG, then run the .JPGs through strtolower and then combine them in the $getlisting array to then be compared with the raw files. Any comments please.
  14. Hi Larry I thought that I'd post this as it might help other php-ers. I have a website which has many images. To facilitate the download of images, I save a reduced image under a directory name e.g. images/activities/P3451098.jpg for thumbnails and slideshows as well as the full size in e.g. images/raw/P3451098.jpg. Then I can offer an enlarged image using <a href = ***><img src...... target = "_blank"> etc. The problem is that as I send the images up using FTP (Filezilla) I can't be sure if all of the reduced images have the corresponding full sized images thanks to advanced dementia. Therefore, I have written a short routine to compare the two directories.... COMMENTS: 1) I was confused at first as to why it didn't work properly until I discovered that glob() is case sensitive, so that it wasn't finding .JPGs so had to run it twice (there is a variety of both depending on which camera they came from). 2) The search routine is not very elegant as it runs through all of the raw files even though it may have found a match in the first file. 3) I know that I could use glob(images/raw/*.*) instead of glob(images/raw/*.*) and in this case it wouldn't make any difference as all files in these directories are .jpgs - it just seems more precise to use *.jpg. I would appreciate any comments from anybody..... <?php //Declare variable $found to avoid undefined variable errors $found = "No"; //Call header which handles security and error messages include ('adminheader.php'); //Create an array $images which lists all of the relevant image directories on the server.. $images = array('4X4', 'activities', 'almonds', 'alojamiento', 'altiplano', 'archery', 'area', 'artifacts', 'baza', 'castillejar', 'castril', 'caving', 'fiestas', 'flowers', 'history', 'huescar', 'kayaking', 'index', 'markets', 'mountaineering', 'mountains', 'museums', 'photography', 'puebla', 'rafting', 'village', 'wildlife', 'activities/activities', 'activities/caving', 'activities/kayaking', 'activities/mountaineering', 'activities/outdoors', 'activities/rafting'); //Create array $raw which will be a listing of all of the large image files on the server $raw = glob('images/raw/*.jpg'); $raw2 = glob('images/raw/*.JPG'); //Work through the $images array so as to compare whether there is a large matching file in the 'raw' directory... foreach($images as $key => $category) { //Start with a header to ID each category.... echo 'CATEGORY:... ' . $category . '<br /><br />'; //Now create a variable ($getlisting) to be able to call only the category that we are interested in... $getlisting = 'images/' . $category . '/*.jpg'; //create an array of the files in this category.. $listing = glob($getlisting); //Run through the $raw array to see if it contains a file that matches the file in the category... foreach($listing as $key => $value) { //Create variable to use in str_replace.. $directory = 'images/' . $category . '/'; // Remove the unwanted directory details.... $value = str_replace($directory, "", $value); //Reduce any JPGs to jpgs... $value = strtolower($value); //Run through the $raw array to find a match.. foreach($raw as $key => $rawvalue) { //Get rid of directory details from $rawvalue... $rawvalue = str_replace("images/raw/", "", $rawvalue); //Bring any .JPGs to .jpgs.... $rawvalue = strtolower($rawvalue); //Do comparison. If raw image matches reduced image then do nothing.. if ($value == $rawvalue) { //If the small and large files match then switch variable $found to 'on'.... $found = "Found"; } } //Run through the $raw array to find a match.. foreach($raw2 as $key => $rawvalue) { //Get rid of directory details from $rawvalue... $rawvalue = str_replace("images/raw/", "", $rawvalue); //Bring any .JPGs to .jpgs.... $rawvalue = strtolower($rawvalue); //Do comparison. If raw image matches reduced image then do nothing.. if ($value == $rawvalue) { //If the small and large files match then switch variable $found to 'on'.... $found = "Found"; } } //If small and large files don't match, then print out the filename .. if ($found != "Found") { echo $value . "<br /><br />"; } //reset $found to "Not found".. $found = "No"; } //Close individual Category foreach echo "<br /><br />"; } //Close all category foreach echo "ALL DONE!"; include ('footer.php'); ?>
  15. STOP PRESS!! Darn it! I have just found a much easier way, thanks to your book (Chapter 2):.... Create array of all jpg files on server in the images/activities/activities directory: $listing = glob("images/activities/activities/*.jpg"); Use 'shuffle() to change the order of the jpg files in the array: shuffle($listing); Use 'foreach()' to trawl through the array to extract the filenames: foreach($listing as $key => $value) { This is a bit of js: echo '<div class="mySlides fade"> <img src = "' . $value . '" style=" display: block; margin: auto; width:80%; border-style: solid; border-width: 2px; border-color: black; vertical-align: top;" alt = "Sorry - image missing." /> </div>'; echo '<div style="text-align:center"> <span class="dot"></span> </div>'; $repeat = 1; } That also solves the issue of repeats. KISS - keep it simple, STOOPID! Regards Max
×
×
  • Create New...