How to get a name inside a php string?

Asked

Viewed 193 times

1

$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]:" 

How to take php part of my string where I have [hba_human.Needle] where hba_human would be the file name, so how can I get what is between the [ ] and has extension .Needle ?

1 answer

0


see working on ideone

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

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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.