RE: [PHP] splitting text solved

2003-06-04 Thread electroteque
i found a snippet somewhere which helped me out and i modified it

?
$input= and a phrase \escaping text\ \howard sux\;


if (preg_match_all('/(?:((?:\\\.|[^\\\])*?)|\b([\S]+)\b)/', $input,
$match)) {
foreach ($match[0] as $key=$value) {
$keyword .=  +.$value;
}
}
echo $keyword;
?

so basically u can have a heap of keywords with some in exact phrases within
quotes and it adds the + for you to make it an AND boolean search string for
mysql full text :D


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Wednesday, June 04, 2003 3:41 PM
To: [EMAIL PROTECTED]
Subject: [PHP] splitting text


hi there , i am building a fulltext search engine which will use the mysql
boolean search features , although it defaults to OR with words between
spaces you have to explictly put a + in front of words so say i typed

some word word2 ,to get both i have to do +some word +word2

how can i split this phrase some word word2 so that i can split some
word and word2 into two different words so i can format them , currently
split on a space will split some word into some and word any ideas ?



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] splitting text after 25 words

2001-08-08 Thread Justin French

Thanks to all who replied, this solution by Chris was bar far the
easiest to implement.

Really appreciate it :)


Chris Lambert wrote:

 $teaser = explode( , $article, 26));
 array_pop($teaser);
 $teaser = implode( , $teaser);


Justin French

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] splitting text after 25 words

2001-08-08 Thread Robert V. Zwink

For future reference using explode and counting the words is not the correct
way to do this.  Your array could be huge, and if you have multiple requests
to the page this would be a horrible idea.  I believe the correct way to do
this is to use MySQL inherent function SUBSTRING_INDEX(str,delim,count)
So for example:

SELECT SUBSTRING_INDEX(column_name, ' ', 20) FROM table_name

would return the first 20 words.  The php way is over-doing it.  If you can
perform the logic in your mysql query, you should.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
From MySQL manual:
http://www.mysql.com/doc/S/t/String_functions.html

SUBSTRING_INDEX(str,delim,count)
Returns the substring from string str before count occurrences of the
delimiter delim. If count is positive, everything to the left of the final
delimiter (counting from the left) is returned. If count is negative,
everything to the right of the final delimiter (counting from the right) is
returned:
mysql select SUBSTRING_INDEX('www.mysql.com', '.', 2);
- 'www.mysql'
mysql select SUBSTRING_INDEX('www.mysql.com', '.', -2);
- 'mysql.com'

This function is multi-byte safe.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Hope this helps!

Robert V. Zwink
DAID Development LLC
http://www.zwink.net/daid.php


-Original Message-
From: Justin French [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, August 08, 2001 7:25 AM
To: Chris Lambert; php
Subject: Re: [PHP] splitting text after 25 words


Thanks to all who replied, this solution by Chris was bar far the
easiest to implement.

Really appreciate it :)


Chris Lambert wrote:

 $teaser = explode( , $article, 26));
 array_pop($teaser);
 $teaser = implode( , $teaser);


Justin French

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] splitting text after 25 words

2001-08-08 Thread jose d lopez

someting i've used.

?php
$storywords = explode( , $storytext);

for ($i=0;$i25;$i++) {
 $teaser = $teaser .   . $storywords[$i];
}
?

? echo $teaser...;?


At 03:57 PM 8/8/2001 +1100, Justin French wrote:
Hi all,

I'd like to split a text block at 25 words, as a teaser for the full
article.  Now I know how to split at a certain character, but i don't
want a half word or anything, so I want (i guess) to hunt for the 25th
occurence of   (a space), and split $text into two new variables,
$text_a and $text_b.

Then I'll prolly want append something like ... click here to read
more on the end of $text_a.

Seems easy enough, but I can't see anything in the manual about
splitting on a numbered occurence of a string (but I could be looking
in the wrong spot :)

Running PHP4 BTW



Thanks heaps in advance
Justin French

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



_
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Splitting Text

2001-08-07 Thread Jordan Elver

Thanks for that. I ended up using your method as using the LEFT function in a 
SELECT only grabs characters.

Cheers,

Jord

On Monday 06 August 2001 17:37, you wrote:
 You can do this several ways... Either use explode():
 http://www.php.net/manual/en/function.explode.php

 ...to split the retrieved data by a space   as the delimeter, then use
 a for() loop to print X number of words... E.g.:

 $array = explode( , $db_string);

 for($i = 0; $i  25; $i++)
   echo $array[$i];

 (That will print the first 25 words...)


 Or, another way to do it is to use strtok() to tokenize the string...
 http://www.php.net/manual/en/function.strtok.php

 The manual has a good example of tokenizing a string into individual
 words...


 -Original Message-
 From: Jordan Elver [mailto:[EMAIL PROTECTED]]
 Sent: Monday, August 06, 2001 5:20 PM
 To: PHP General Mailing List
 Subject: [PHP] Splitting Text


 Hi,
 Can anyone give some pointers for my problem.
 I want to pull articles out of a db and then show the first x number of
 words
 with a read more link to the rest of the article.

 Could someone point me in the right direction. I've seen a code snippet
 for
 this, but now I can't find it :-(

 TIA,

 Jord

-- 
Jordan Elver
Web Developer
The InternetOne UK Ltd

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Splitting Text

2001-08-07 Thread Robert V. Zwink

For future reference using explode and counting the words is not the correct
way to do this.  Your array could be huge, and if you have multiple requests
to the page this would be a horrible idea.  I believe the correct way to do
this is to use MySQL inherent function SUBSTRING_INDEX(str,delim,count)
So for example:

SELECT SUBSTRING_INDEX(column_name, ' ', 20) FROM table_name

would return the first 20 words.  The php way is over-doing it.  If you can
perform the logic in your mysql query, you should.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
From MySQL manual:
http://www.mysql.com/doc/S/t/String_functions.html

SUBSTRING_INDEX(str,delim,count)
Returns the substring from string str before count occurrences of the
delimiter delim. If count is positive, everything to the left of the final
delimiter (counting from the left) is returned. If count is negative,
everything to the right of the final delimiter (counting from the right) is
returned:
mysql select SUBSTRING_INDEX('www.mysql.com', '.', 2);
- 'www.mysql'
mysql select SUBSTRING_INDEX('www.mysql.com', '.', -2);
- 'mysql.com'

This function is multi-byte safe.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Hope this helps!

Robert V. Zwink
DAID Development LLC
http://www.zwink.net/daid.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] splitting text after 25 words

2001-08-07 Thread Chris Lambert

$teaser = explode( , $article, 26));
array_pop($teaser);
$teaser = implode( , $teaser);

/* Chris Lambert, CTO - [EMAIL PROTECTED]
WhiteCrown Networks - More Than White Hats
Web Application Security - www.whitecrown.net
*/

- Original Message - 
From: Justin French [EMAIL PROTECTED]
To: php [EMAIL PROTECTED]
Sent: Wednesday, August 08, 2001 12:57 AM
Subject: [PHP] splitting text after 25 words


| Hi all,
| 
| I'd like to split a text block at 25 words, as a teaser for the full 
| article.  Now I know how to split at a certain character, but i don't 
| want a half word or anything, so I want (i guess) to hunt for the 25th 
| occurence of   (a space), and split $text into two new variables,
| $text_a and $text_b.
| 
| Then I'll prolly want append something like ... click here to read 
| more on the end of $text_a.
| 
| Seems easy enough, but I can't see anything in the manual about 
| splitting on a numbered occurence of a string (but I could be looking
| in the wrong spot :)
| 
| Running PHP4 BTW
| 
| 
| 
| Thanks heaps in advance
| Justin French
| 
| -- 
| PHP General Mailing List (http://www.php.net/)
| To unsubscribe, e-mail: [EMAIL PROTECTED]
| For additional commands, e-mail: [EMAIL PROTECTED]
| To contact the list administrators, e-mail: [EMAIL PROTECTED]
| 
| 
| 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] splitting text after 25 words

2001-08-07 Thread karthik

Hi,

Best way i guess would be traverse the whole string and check for space.
Have a counter var which keeps count of the space. At the 25th occurence do
something like this -

$text_a = substr($text, 1, $i);

i assume that $i is the increment var in the loop.

$text_b = substr($text, $i+1);

This should give u the strings in 2 vars.

Now u can add anything with $text_aClick here .$text_b

Hope i was helpful,
Karthik.

- Original Message -
From: Justin French [EMAIL PROTECTED]
To: php [EMAIL PROTECTED]
Sent: Wednesday, August 08, 2001 10:27 AM
Subject: [PHP] splitting text after 25 words


 Hi all,

 I'd like to split a text block at 25 words, as a teaser for the full
 article.  Now I know how to split at a certain character, but i don't
 want a half word or anything, so I want (i guess) to hunt for the 25th
 occurence of   (a space), and split $text into two new variables,
 $text_a and $text_b.

 Then I'll prolly want append something like ... click here to read
 more on the end of $text_a.

 Seems easy enough, but I can't see anything in the manual about
 splitting on a numbered occurence of a string (but I could be looking
 in the wrong spot :)

 Running PHP4 BTW



 Thanks heaps in advance
 Justin French

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Splitting Text

2001-08-06 Thread Alfredeen, Johan

Jord,
  I would accomplish this through SQL. You could use SELECT LEFT(mycolumn,x)
FROM mytable WHERE ...
and then display that along with a link to a page where you select the whole
string on that particular article ID. In fact, I do this exact thing on my
site.

Or you could read the whole string into an array, and use the PHP function
to retrieve the substring you want. I prefer the first option however.

Good luck,

Johan Alfredeen
PongWorld.com
www.pongworld.com

-Original Message-
From: Jordan Elver [mailto:[EMAIL PROTECTED]]
Sent: Monday, August 06, 2001 3:20 PM
To: PHP General Mailing List
Subject: [PHP] Splitting Text


Hi, 
Can anyone give some pointers for my problem.
I want to pull articles out of a db and then show the first x number of
words 
with a read more link to the rest of the article. 

Could someone point me in the right direction. I've seen a code snippet for 
this, but now I can't find it :-(

TIA,

Jord

-- 
Jordan Elver
http://www.jordanelver.co.uk

Oops, my brain just hit a bad sector!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Splitting Text

2001-08-06 Thread Matthew Loff


You can do this several ways... Either use explode():
http://www.php.net/manual/en/function.explode.php

...to split the retrieved data by a space   as the delimeter, then use
a for() loop to print X number of words... E.g.:

$array = explode( , $db_string);

for($i = 0; $i  25; $i++)
echo $array[$i];

(That will print the first 25 words...)


Or, another way to do it is to use strtok() to tokenize the string...
http://www.php.net/manual/en/function.strtok.php

The manual has a good example of tokenizing a string into individual
words...


-Original Message-
From: Jordan Elver [mailto:[EMAIL PROTECTED]] 
Sent: Monday, August 06, 2001 5:20 PM
To: PHP General Mailing List
Subject: [PHP] Splitting Text


Hi, 
Can anyone give some pointers for my problem.
I want to pull articles out of a db and then show the first x number of
words 
with a read more link to the rest of the article. 

Could someone point me in the right direction. I've seen a code snippet
for 
this, but now I can't find it :-(

TIA,

Jord

-- 
Jordan Elver
http://www.jordanelver.co.uk

Oops, my brain just hit a bad sector!

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED] To
contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]