me1000 Posted March 7, 2006 Share Posted March 7, 2006 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 contentwhile($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] Quote Link to comment Share on other sites More sharing options...
dcro2 Posted March 7, 2006 Share Posted March 7, 2006 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] Quote Link to comment Share on other sites More sharing options...
me1000 Posted March 7, 2006 Author Share Posted March 7, 2006 Thanks taht did it! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.