<?php
function extrairPedaco($texto, $inicio, $delimitador){
}
$texto = "The blood A+ Tend to be cooperative, sensitive, clever, passionate and smart.";
$referencia = "blood";
$tipos = ['+', '-'];
foreach ($tipos as $tipo){
$pedaco = extrairPedaco($texto, $referencia, $tipo);
$pedaco = strtoupper($pedaco); // Converte para maiúsculo, eliminando a necessidade de usar a variável "result". switch($pedaco){
case "A+":
echo "Ideal donor: A+<br>Other donors: A+ or O+<br>Only if no Rh(+) found: A- or O-";
break;
case "A-":
echo "Ideal donor: A-<br>Other donors: A- or O-";
break;
case "B+":
echo "Ideal donor: B+<br>Other donors: B+ or O+<br>Only if no Rh(+) found: B- or O-";
break;
case "B-":
echo "Ideal donor: B-<br>Other donors: B- or O-";
break;
case "AB+":
echo "Ideal donor: AB+<br>Other donors: AB+ or A+ or B+ or O+<br>Only if no Rh(+) found: AB- or A- or B- or O-"; break;
case "AB-":
echo "Ideal donor: AB-<br>Other donors: AB- or A- or B- or O-";
break;
case "O-":
echo "Ideal donor: O-<br>Other donors: O-";
break;
case "O+":
echo "Ideal donor: O+<br>Other donors: O+<br>Only if no Rh(+) found: O-";
break;
default:
// Faça algo aqui caso as comparações acima falhem.
echo "No blood found\n";
break;
}
}
PD9waHAKCmZ1bmN0aW9uIGV4dHJhaXJQZWRhY28oJHRleHRvLCAkaW5pY2lvLCAkZGVsaW1pdGFkb3IpewoJJHN1YiA9IHN1YnN0cigkdGV4dG8sIHN0cnBvcygkdGV4dG8sICRpbmljaW8pICsgc3RybGVuKCRpbmljaW8pLCBzdHJsZW4oJHRleHRvKSk7CglyZXR1cm4gc3Vic3RyKCRzdWIsIDEsIHN0cnBvcygkc3ViLCAkZGVsaW1pdGFkb3IpKTsKfQoKJHRleHRvID0gIlRoZSBibG9vZCBBKyBUZW5kIHRvIGJlIGNvb3BlcmF0aXZlLCBzZW5zaXRpdmUsIGNsZXZlciwgcGFzc2lvbmF0ZSBhbmQgc21hcnQuIjsKJHJlZmVyZW5jaWEgPSAiYmxvb2QiOw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LSBvciBPLSI7IGJyZWFrOwogICAgICAgICAgICBjYXNlICJBQi0iOiAKICAgICAgICAgICAgCWVjaG8gIklkZWFsIGRvbm9yOiBBQi08YnI+T3RoZXIgZG9ub3JzOiBBQi0gb3IgQS0gb3IgQi0gb3IgTy0iOyAKICAgICAgICAgICAgCWJyZWFrOwogICAgICAgICAgICBjYXNlICJPLSI6ICAKICAgICAgICAgICAgCWVjaG8gIklkZWFsIGRvbm9yOiBPLTxicj5PdGhlciBkb25vcnM6IE8tIjsgCiAgICAgICAgICAgIAlicmVhazsKICAgICAgICAgICAgY2FzZSAiTysiOiAgCiAgICAgICAgICAgIAllY2hvICJJZGVhbCBkb25vcjogTys8YnI+T3RoZXIgZG9ub3JzOiBPKzxicj5Pbmx5IGlmIG5vIFJoKCspIGZvdW5kOiBPLSI7IAogICAgICAgICAgICAJYnJlYWs7CgkJCWRlZmF1bHQ6CgkJCSAgICAvLyBGYcOnYSBhbGdvIGFxdWkgY2FzbyBhcyBjb21wYXJhw6fDtWVzIGFjaW1hIGZhbGhlbS4KCQkJICAgIGVjaG8gIk5vIGJsb29kIGZvdW5kXG4iOwoJCQkgICAgYnJlYWs7CiAgICAgICAgfSAKfQ==