2009-11-08 4 views

Répondre

9

Essayez ceci:

$line="Hello! You are with Andy. Good job!"; 
$bad=array("Hello! You are with ",". Good job!"); 
$name = str_replace($bad,"",$line); 
echo $name; 
+0

Ceci est chaud. J'aime la propreté et l'efficacité. – Strawberry

1

Comme il ressemble à la seule chose qui change dans vos phrases est le nom, vous pouvez utiliser str_ireplace comme ceci:

$sentence = "Hello! You are with Andy. Good job!"; 
$name = str_ireplace(array('Hello! You are with ', '. Good job!'), array('',''), $sentence); 
4

Vous pouvez essayer des expressions régulières :

$matches = array(); 
preg_match("/Hello! You are with (.*?)\. Good job!/",$input,$matches); 
$name = $matches[1]; 
+0

@stereofrog C'est plus lent que 'str_replace'. – chelmertz

Questions connexes