Jump to content

tijmenamsing

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by tijmenamsing

  1. Neat, never heard and works like a charm without installing anything new. I have no how it works though ;p
  2. wow thanks all for the replies! I don't have the knowledge yet to understand all of the code, but I think kicken's function is most complete and works out best for me. I get one warning though, which occurs when I add a closing tag when there is no opening tag of it. Warning: strpos() [function.strpos]: Offset not contained in string in #/test.php on line 12 line 12 being: while (($pos=strpos($html, '<', $pos)) !== false){ Any idea how to fix this? And if it's not too much to ask, could you add some comments to the function?
  3. That's the way my function worked as far as I can remember. And I called it like: tags("<div>", "</div>", $summary), the paramaters being (opening tags, closing tags, haystack). I used to call it only for div and span but now I would like a function that checks for all occuring opening tags automatically.
  4. Hello, I'm working on a page where users can add articles by writing text in textareas with a WYSIWYG editor. When they submit the form it's saved in a database. As a summary of the article i grab the first 800 characters of the article, but as you could imagine there might occur html tags like <div> or <span> in the summary which are not closed. To prevent this from ruining my page layout when their articles are posted on the wegbsite I could use strip_tags but I'd like to keep the format, also this would delete images. I couldn't think of another solution then a function which checks for open tags and if so; add closing tags at the end of the summary. I already made a similar function a while back, but that one only checks for <div> and <span>, as those are the worst.. The nasty part is that I kind of deleted that function accidentally, and I can't fully remember how I wrote that.. So what I would like to have is a function that checks for all unclosed html tags and add the associated closing tags, in the right order, at the end of the summary. Any help getting on the right track is appreciated.
  5. Sir, you are brilliant. Hadn't even thought of this way. thanks!
  6. Hi, I have a page where users can add some text and additionally images. This is done through a textbox and NicEditor. Users are able to add images with any size, by either uploading it or usea URL. The problem occurs when they add a image wider than 560px, because then it ruins my lay out. This is why i want to add style="max-width:560px;" at the end of all image tags. So for example <img src="http://images.com/image.jpg" style="max-width:560px;"> If made the following code but this only works when a user adds just one image, i need it to work also when there are multiple images. <?php $img = '<img src="http://images.com/image.jpg">'; $imgstart = strpos($img,'<img'); // get position of <img if($imgpstart !== false) { $imgend = strpos($img,'>'); // get position of > $width = ' style="max-width:560px;">'; $img= substr_replace($img, $width, $imgend, 1); // replace > with $width } echo $img; ?> This may not be the safest and best solution so i'd like some help with a function which finds all images in a string and give them a max-width. thanks!
  7. Thanks for you reply, i got it working now! Instead of your idea to search for the string as a whole when a user enters quotes, i added a checkbox which does almost the same thing. I also added a filter so the user can select in which column the string should be searched for. code : <?php if(!empty($_GET['zoekopdr'])) { $zoekopdr = trim($_GET['zoekopdr']); if ((!isset($_GET['zArtikel']) || $_GET['zArtikel'] == "off") && (!isset($_GET['zTitel']) || $_GET['zTitel'] == "off") && (!isset($_GET['zJaar']) || $_GET['zJaar'] == "")) { // if no checkbox is selected echo "Geen zoekgebied opgegeven."; } elseif (strlen($zoekopdr) < 3) { // if string length < 3 echo "De zoekopdr moet minimaal 3 karakters bevatten."; } else { require_once('dbcon.php'); if (isset($_GET['zExact']) && $_GET['zExact'] == "on") { // if user wants to search for the complete string $zoekq = " LIKE '%" . mysql_real_escape_string($zoekopdr) . "%' "; } else { // if user wants to search for seperated words $parts = explode(' ',$zoekopdr); $parts = array_filter($parts); // filter the array to get rid of empty indexes. $parts = array_map('mysql_real_escape_string',$parts); // escape SQL data. $zoekq = " LIKE '%" . implode('%',$parts) . "%' "; } $query = "SELECT * FROM n_artikelen WHERE "; if (isset($_GET['zJaar']) && $_GET['zJaar'] != "") { // if user only wants results from the selected year $query .= " YEAR(publicatie) = '" . $_GET['zJaar'] . "'"; $x = true; } if (isset($_GET['zArtikel']) && $_GET['zArtikel'] == "on") { // if user wants to search in column1 if ($x == true) { $query .= " AND "; } $query .= " volledig_artikel $zoekq"; $y = true; } if (isset($_GET['zTitel']) && $_GET['zTitel'] == "on") { // if user wants to search in column2 if ($x == true && $y == false) { $query .= " AND "; } if ($y == true) { $query .= " OR "; } $query .= " titel $zoekq"; } $result = mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) < 1) { // if there are no results echo "De zoekopdracht '{$zoekopdr}' heeft geen resultaten."; } else { // else print the results while ($row = mysql_fetch_array($result, MYSQL_NUM)) { artikelelement($row); } } } } ?> Any ideas on how to sort on closest match?
  8. Hello, I'm making a website which includes an articles page. I want users to be able to search for particular articles. For this search function I used the Simple SQL Search tutorial from phpfreaks (http://www.phpfreaks.com/tutorial/simple-sql-search). It's working quite well but i'd like to expand it a little. The most important thing i want changed is what happens when users enters a string which holds multiple words. The function from the tutorial perceives these words as one string and searches for that string as a whole. For example when a user enters 'winter 2012' and an article holds the string 'winter of 2012', the function returns no matches. This is, ofcourse, not the way i'd like it to function. I've managed to seperate the words and search for them individually by using explode and foreach, but now i'm getting duplicate results when an article holds mulitple words from the users' entry string. My idea to fix this was to make an array with the article id's of the articles that have matched, and then to exclude them from the SQL query for the next word from the search string by using 'NOT IN $array' in the where clause. Unfortunately i haven't managed to succeed with this so far and that's why i ask for your help.. This my search function: function zoekopdracht() { require('dbcon.php'); $zoekopdr = trim($_GET['zzoek']); $zoekopdr = strip_tags($zoekopdr); if (strlen($zoekopdr) < 3) { echo "De zoekopdr moet minimaal 3 karakters bevatten."; } else { $zoekopdr = explode(" ", $zoekopdr); foreach($zoekopdr as $zoekterm) { $zoekopdrDB = mysql_real_escape_string($zoekterm); $searchSQL = "SELECT * FROM n_artikelen WHERE "; $types = array(); $types[] = isset($_GET['zartikel'])?" volledig_artikel LIKE '%{$zoekopdrDB}%'":''; $types[] = isset($_GET['ztitel'])?" titel LIKE '%{$zoekopdrDB}%'":''; $types[] = isset($_GET['zjaar'])?" YEAR(publicatie) LIKE '%{$zoekopdrDB}%'":''; $types = array_filter($types, "removeEmpty"); // removes any item that was empty (not checked) if (count($types) < 1) { $types[] = "volledig_artikel LIKE '%{$zoekopdrDB}%'"; // use the artikel + titel as a default search if none are checked $types[] = "titel LIKE '%{$zoekopdrDB}%'"; } $searchSQL .= implode(" OR ", $types) . " ORDER BY publicatie LIMIT 0,10"; $searchResult = mysql_query($searchSQL) or die(mysql_error()); if (mysql_num_rows($searchResult) < 1) { echo "De zoekopdracht '{$zoekopdr}' heeft geen resultaten."; } else { while ($row = mysql_fetch_array($searchResult, MYSQL_NUM)) { artikelelement($row); // function that outputs the result of $row[] } } } } } Additionally, if this problem is fixed, i'd love to see a way to sort the results on closest match (article which matches two words > article which matches one word). Thanks!
×
×
  • 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.