Jump to content

[SOLVED] Problem


shage

Recommended Posts

$body=$randbody;
$counter=substr_count($body,"(");

for($c=0;$c<$counter;$c++)
{
$splitted=str_split($body);
for($i=0;$i<count($splitted);$i++)
{

if($splitted[$i]=="(")
{
	while($splitted[$i]!=")")
	{
		$con.=$splitted[$i];
		$i++;
	}
}
}

$string=$con;
$result=explode("(",$string);
$values=explode(",",$result[1]);
$tot=count($values);
$tot-=2;
$random=rand(0,$tot);
$res=$values[$random];
$body=substr_replace($body,$res,strpos($body,"("),(strpos($body,")")-strpos($body,"(")+1));
}
$randbody=stripslashes($body);

 

Explain to me why in the body everywhere i put (whatever,test,random,) is suppose to random the text in the () it does it but it keeps the first () and randoms it everywhere () is located, i want to be able to random () different depending on whats in ()

Link to comment
Share on other sites

is it what you try

<?php
$body = 'I am (15,23,96) y old and I go to (Paris,Wien,Los Angeles,Rim).';
$body = explode('(', $body);
$out = $body[0];
for ($i = 1; $i < count($body); $i++){
$con = explode(')',$body[$i]);
$pos = explode(',', $con[0]);
$out .= $pos[rand(0, count($pos)-1)]. $con[1];
}
echo $out;
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.