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??

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.

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.

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

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];
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.