0

Hi,

I want to find random string between main string.

Suppose
$string="Sign up for Facebook to connect with Jean Profession";

I want do that ..

random word who having length greater than 4 and word not equal to Facebook.

How to do this??

4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by cwarn23
0

hi,

my string is
$string="Sign up for Facebook to connect with Jean Profession";

i want to find word randomly from string

like :- connect or Profession whose length >4 and this word not is a facebook.

0

hi,

my string is
$string="Sign up for Facebook to connect with Jean Profession";

i want to find word randomly from string

like :- connect or Profession whose length >4 and this word not is a facebook.

Yes, you described that, which is why I posted a link describing how to do it.

Edited by ShawnCplus: n/a

0

hi,

my string is
$string="Sign up for Facebook to connect with Jean Profession";

i want to find word randomly from string

like :- connect or Profession whose length >4 and this word not is a facebook.

You can use regular expressions or string functions.

String functions: http://us2.php.net/manual/en/book.strings.php
Probably the simplest way to go about it is to explode() the string into an array of words.

eg:

$array = explode(" ", $string);

Then loop each array values (each word) counting characters with strlen().

For an intro to regular expressions see: http://www.regular-expressions.info/

It also goes into it in depth after a while. Regex is a really useful tool to learn, and is implemented similarly across programming languages. The flavor PHP currently uses is PCRE. http://www.pcre.org/

The PHP docs: http://www.php.net/pcre

0

Try this:

<?
$string='Sign up for Facebook to connect with Jean Profession';
$word=explode(' ',$string);
$b=(count($word)-1);
$b=mt_rand (0,$b);
echo $word[$b];
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.