How to get a name inside a string in php?

2
$resultado = "spawn needle /var/www/html/trabalho/arquivo/emboss/needle/alvos.txt /var/www/html/trabalho/arquivo/emboss/needle/modelos.txt Needleman-Wunsch global alignment of two sequences Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Gap opening penalty [10.0]: 10.0 Gap extension penalty [0.5]: 0.5 Output alignment [hba_human.needle]:" 

and has .needle extension?

    
asked by anonymous 04.08.2017 / 22:30

1 answer

0

See working on ideone

Use strripos Find the position of the last occurrence of a case-insensitive string in a string. Look for the positions of [ and ]

Then use substr - Returns a part of a string

$resultado = "spawn needle /var/www/html/trabalho/arquivo/emboss/needle/alvos.txt /var/www/html/trabalho/arquivo/emboss/needle/modelos.txt Needleman-Wunsch global alignment of two sequences Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Warning: Unknown swissprot line type ' ' Gap opening penalty [10.0]: 10.0 Gap extension penalty [0.5]: 0.5 Output alignment [hba_human.needle]:";

$posInicio  = strripos($resultado, "[");

$posFim  = strripos($resultado, "]");

//quantidade de caracteres que serão extraídos contados a partir da posição inicial
$quant= ($posFim-$posInicio-1);

echo substr($resultado, $posInicio+1, $quant);
    
04.08.2017 / 23:22