Nasıl bir cümlenin parçaları kaldırırım?

3 Cevap

Andy ile vardır. İyi iş!

Hello! You are with Naruto-san. Good job!
Hello! You are with DragonFangîŠ. Good job!
Hello! You are with Adam Chan. Good job!
Hello! You are with Dudeî„­. Good job!
Hello! You are with Signore. Good job!
Hello! You are with Athena. Good job!
Hello! You are with EL NwithJA. Good job!
Hello! You are with Keeperî„­â„¢. Good job!

PHP kullanarak, nasıl ben "Merhaba! You ile vardır" ve şerit olabilir. "İyi iş!"? bu yüzden bir değişken adını saklayabilirsiniz.

3 Cevap

Bu deneyin:

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

Bazı düzenli ifadeler deneyebilirsiniz:

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

Bu cümle değişiklikleri tek şey gibi görünüyor adıdır olduğundan, str_ireplace Bu gibi kullanabilirsiniz:

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