Limiting Words

Apr 22, 2007

I am trying to get a list of news stories from a database and list them, limiting them to a just 100 characters, and rounding them off to the nearest whole sentance, with a Read More link to read in full. I have written the code, but its not working. Code:

View 2 Replies


Limiting The String Length By The Number Of Words?

I have a string in the form of "word1-word2-word3-word4-word5-word-6-word7", but I want to shorten it to 5 words only.

View 11 Replies

$words Array Have Many Words , It Work Only With First Words?

i have array :

PHP Code:
$array1= array("donkey","cat","****");

it work some times , but if $words array have many words , it work only with first words , so , what's your opinion ? and it this method is true ? or there are anothr method ?

View 5 Replies

Calculate The Number Of Words/characters Between 2 Given Terms/words?

Basically - I want to calculate the "Proximity" of various terms. By "proximity" I means Specifically the number of spaces/characters/words that sit between them.


Terms = Word1 / Word2
Chunk = "blah Word1 blah blah blah blah blah Word2 blah"
Proximity = Word1-Word2:5

THe script would see the 2 terms, locate them and then see the distance based on the words that lay between them. A more advanced version would be to examine the semantic structure - and identify whether the terms occur within the same semantic element, or a sibling, or a parent etc. Thus proximity discovery of terms may be within the same paragraph, or in sequential paragraphs, or under the same "parent" (heading) but otherwise separate etc. Further - introducing things like word stemming/relationships/soundings at a later date may be useful too.

I've looked around the net (Google, here, php forums, php script sites). Not seeing anything like it. I can see tools on some sites that do similar (limited) - usually SEO based tools. I want to be able to apply this to "text" in general ... as I may apply it to uploaded word/txt files etc. I'm not seeing any real examples - so I can only assume it's mroe than a trifle to code it. How would I handle variant order of the words (Word1+Word2 / Word2+Word1)? How could I handle identifying proximity within/outside of the same element/structure?

View 1 Replies

Bold Some Words In A String And Remove Some Unbold Words?

I am creating an Image Search Engine. Currently, my script does bold the matching words on the keyword. But, some keywords are too long just like the followings. When I search for shah rukh khan, there is an image with the following keyword.

25216d1235653089 shahrukh khan s
wallpaper shah rukh actor

As you see, the above keyword is too long. So, I need it to be like the following one.


Currently, I am using the following code but it requires a space before and after the bold tags. So, if the 1st word is bold, it displays the whole keyword.

$img_keyword = preg_replace('/(.*?) <b>(.*?)</b> (.*?)/us'," <b>$2</b> ",$img_keyword);

View 2 Replies

Counting Words And Cut After Specific Total Words

This is my code to count words in a post: PHP Code:

View 6 Replies

Perform Search Onto Words And Display The 2 Words

so far on page one it takes word from text box and produces search on datebase for that word then produces correctly over the folling pages using pagination. question is i want it to now perform search onto words and display the 2 words. code is below. :_

$carrymake = (isset($_POST['carrymake']))? $_POST['carrymake'] : $_GET['carrymake'];

$carrymodal = (isset($_POST[carrymodal ]))? $_POST[carrymodal ] : $_GET[carrymodal ];

i want to know now how to include the second varible in this code here:-

// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo '<a href="'.$_SERVER['PHP_SELF'].'?page='.$prev.'&carrymake='.$carrymake.'"><<Previous</a>&nbsp;'

View 1 Replies

Preg_match_all : Replace Multiple Words With Different Words?

$post[message] is the text of a post from my forum.

I wanted to take out all the text and keep only the text between [TAG1] tags

here is a part of the code i am using to do that:

$string = $post[message];
$tag = "TAG1";
preg_match_all("#[".$tag."](.*)[/".$tag."]#Ui", $string, $matches);


View 14 Replies

Replace Words - Ignore Words Between Brackets?

I'm using an ubb parser to convert several codes within brackets to html codes. I want to use a string replacer aswell to replace some unwanted words.

Now, I'm using this:

foreach($f AS $value) {
$escapeNamesArray[] = '/'.$value['woord'].'/i';
$escapeNamesReplace[] = '<span style="color: gray;">'.$value['vervanging'].'</span>';


When I want to replace the word "Hello" to "Hey", everything is working fine. But when I place the word "Hello" between brackets, for example:


The word "Hello" is replaced aswell. How can I change the pattern of the preg_replace function to ignore words between brackets?

View 4 Replies

Wrap Words Or Words Sequences Which Have Not Been Already Wrapped?

I'm trying to wrap words and words sequence from a given list with preg_replace. It almost works, but there are some use cases it doesn't and I can't figure it how. For instance I do this:

// sort by descending length
usort($this->_keywords, function($a,$b){return(strlen($a)<strlen($b));});
// wrapper is -%string%-


From this keyword list:

sit amet


I'd like to result in:

-Lorem- -ipsum- dolor -sit amet-,
consectetur adipiscing elit. Phasellus
rhoncus venenatis orci sed porta. Sed


View 2 Replies

Converts Singular Words To Plural Words

I am looking for a class that converts Singular words to Plural words. My aim is to take something like Story for a model name and create a Story.php file and a stories.php file. I already have the generator class ready to roll just hoping there is some prebuilt class for converting singular to plural word otherwise i'll start this the most expected ones and work from there.

View 2 Replies

Organize Words So Can Fit The Most Number Of Words In A Given Length?

I'm looking for a way to do the following. I have a list of words of various char lengths. I have a limited number of chars I can use in a given strings size. I'd like to organize the words to fit as many of them as I can in a given string without going over the limit or cutting any of the words off.



I have a limit of 140 characters to fit them all in, including spaces. If I have more names than space avail in that string, I'd like to generate another string using the same function as described above until all the names in the list are used.

View 1 Replies

Punctuate Words If It Contains More Then X Number Of Words?

When a word gets to long it messes the text up.... how can I fix this?


Make a word with 4 chars like "cats" into "ca..."

How would I do this?

View 1 Replies

Count The Number Of Words Between Two Words?

How can i count the number of words between two words?


Now i have this regular expression:


View 3 Replies

Reads In A String And Reverses All Of The Words Inside Of The String (the Words Stay In The Same Position But Are Reversed)

A function that reads in a string and reverses all of the words inside of the string(the words stay in the same position, but are reversed).

function(String sentence){
String word="";
String reversedSentence;
for(int i = 0; i< sentence.length; i++){
if(sentence[i] == ' '){
reversedSentence += reverse(word);
word = "";

View 9 Replies

Page Limiting

I have pages for the results (as you can see 1 2 3 4 and 5) ... how do I get it to where it only shows 4 pages at a time? For eample , it will show

1 2 3 4 5 >> Next then when they get to the 4th page it will then show 5 6 7 8 , for eample .. then when they get on the 8th page it iwll show 9 10 11 12 , and so on. Code:

View 20 Replies

Limiting SQL Rows

is there a way in MySQL where I can limit the database itself (Not the output) to 10 rows?

what i am aiming to do is on my website have a list of recently added products to the main database and it stores the 10 most recently added products to the database, and removes the oldest record.

View 1 Replies

Limiting An Array

Is it possible to limit an array? For example to display parts of an array (that has say 22 bits to it) but only display 4 bits of it?

View 1 Replies

Limiting Size

I have a query that im using in a paginated page

e.g. "select * from news"

what i want to do is for the first page get the first 20 say and then for the second get from 21 to 40 and so on. Is this possible in the query? I can obviously code it up to do the logic in PHP but thats going to be inefficent and people might laugh at me behind my back.

View 2 Replies

Limiting Number

i'm working on an event listing site. when someone lists an event, they can upload 3 images. Rather than uploading every single image to a single directory, i'd like to break the uploaded images out into a bunch of different directories. otherwise, any attempts to view the contents of the user image folder could result in a really LONG wait as we list a billion images. I'd like to limit the contents of any given directory to a thousand items.

I'd also like to support a very large number of events and images (1 billion? 10 billion?). I realize that many images might overload a single drive on any server, but am still determined to do it. Seems to me that some sort of recursive function might be necessary? It's easy enough to turn an event id into a folder. it's also not so hard to make a new subdirectory so there are no more than 1,000 events in a irectory. what's more difficult is when we exceed 1 million images. then my top level directory would have more than a thousand images in it.

View 7 Replies

Limiting Selection

I have checkboxes on a form that should only allow up to four selections. What would I need to add to this code to limit the selection to 4. Now it lets you select more than 4.

<td class="resultsColumnName" id="vciColumnTitle" valign="bottom" align="center"><strong>VCI</strong><br>Cushion</td>
<td class="resultsColumnName" id="checkboxColumnTitle" valign="bottom" align="center"><strong><h2>Choose up<br> to 4 Shoes to<br> Compare</h2></strong></td>
do { ?>
<td class="shoeNameResults"><?=$myrow[product_name];?></td>
<td class="shoeTciResults" align="center" width="30"><?=$myrow[tci];?></td>
<td class="shoeVciResults" align="center" width="30"><?=$myrow[vci];?></td>
<td class="shoeCheckboxResults" align="center" valign="top" height="20"><input type=checkbox name=shoes[] value="<?=$myrow[product_image]?>"></td>
} while ($myrow = mysql_fetch_array($result)); ?>
<? } else {
echo "Sorry, no records were found";
} ?></td>
<td width="5%">&nbsp;</td>

View 3 Replies

Limiting Text

I have a field in my database named about and I want to limit the amount of characters outputted (to 100)of this, so I thought it would be done like so:


$query = mysql_query("SELECT * FROM players ORDER BY RAND() LIMIT 1") or die(mysql_error());
$text = substr($about,0,100);

while($row = mysql_fetch_array($query)) {

echo '<h3>'. $row['player_name'] .'</h3>'."
echo '<div class="profile_image"><img src="images_two/odhiambo_delete.jpg" /></div>'
echo '<div class="profile_text">'. $row['text'] .'</div>'."


However, that does not seem to work, where am I going wrong?

View 2 Replies

Limiting A Selection

I have a table in my database that contains fields relating to addresses. What I want to do is to give the user a choice to view all the locations from a certain county. As there can be multiple instances of a county in the table how do I ensure the county only gets displayed once. For example in the table I may have 5 entries which are:


When I retrieve all the information from the table I want to display only


View 2 Replies

Limiting Products

I have never been able to figure out how to show more than one product within a table row, and limit my products in that row to whatever. 3 or 4.

View 3 Replies

Limiting To Certain Amout

Using the substr function I have limited a string to a certain amount of chars. PHP Code:

echo substr($row["refer"], 0, 50);

I have noticed quite a few websites add.

View 2 Replies

Limiting Query Between ..

How is it possible to limit a query to a designated number of records. not sure if Im wording this correctly.. My table has the first field to "id" it is a INT, primary & is auto increment:

query only to say
id = 655 to 2222 range ?
where 'name' LIKE 'jugs'

View 2 Replies

Copyrights 2005-15, All rights reserved