2017-05-28 2 views

Antwort

1

Versuchen Sie folgendes:

<?php 
    $sentence = "This is a banana (fruit)"; 
    $a = stripos($sentence,"("); 
    $b = stripos($sentence,")"); 
    echo substr($sentence, $a, $b); 
?> 
0

Verwenden preg_rpelace Funktion:

<?php 
$str = "This is a banana (fruit)"; 
echo preg_replace('/.*\((.*)\).*/','$1',$str); 
?> 
-1

oder Sie können mit der Erfassung der Gruppen verwenden preg_match:

$pattern = '/\((\w+)\)/'; 
$str = "This is a banana (fruit)"; 
preg_match($patern,$string,$match); 
print_r($match); 

Array 
(
    [0] => (fruit) 
    [1] => fruit 
) 
Verwandte Themen