Jump to content

Recommended Posts

Ok ive started on a new search, but I dont know how to limit hte # of charactors it returns. Its also showing HTML and I only want it to show plain text, but on the output results of it its showing the whole page, I want to limit the number of characters it returns to like 50 or 100.

heres the code of my page

[code]<?
require_once ("config.php");

$search=$_POST["search"];

//get the mysql and store them in $result
//change whatevertable to the mysql table you're using
//change whatevercolumn to the column in the table you want to search
$result = mysql_query("SELECT * FROM $sTableName WHERE PAGE_CONTENT LIKE '%$search%'");

//grab all the content
while($r=mysql_fetch_array($result))
{    

// change page type #'s to words
$page_type = $r["PAGE_TYPE"];
$new_type = "";

if ($page_type == 1) {
$new_type = "Home";
} else if ($page_type == 2) {
$new_type = "People";
} else if ($page_type == 3) {
$new_type = "Things";
} else if ($page_type == 4) {
$new_type = "Ships";
} else if ($page_type == 5) {
$new_type = "Types";
} else if ($page_type == 6) {
$new_type = "Tech";
} else if ($page_type == 7) {
$new_type = "Food";
} else {
$new_type = "Unknown";
}

   //the format is $variable = $r["nameofmysqlcolumn"];
   //modify these to match your mysql table columns
  
   $title=$r["PAGE_TITLE"];
   $message=$r["PAGE_CONTENT"];
   $id=$r["ID"];
   $link = '<a href ="index.php?page_id='.$id.'">'.$new_type.': '.$title.'</a>';
  
   //display the row
   echo "$link <br> $message <br>";
}
?>[/code]



Link to comment
https://forums.phpfreaks.com/topic/4279-limiting-of-search-results-charactors/
Share on other sites

You could use substr() to limit the characters to 50, 100, etc.

[code]string substr ( string string, int start [, int length] )[/code]
So, I'm guessing in your case it would be:

[code]$message = substr($message, 0, 50);[/code]
For viewing only text, you could use the strip_tags() function

[code]string strip_tags ( string str [, string allowable_tags] )[/code]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.