How to search a word at an interval in the sentence

Asked

Viewed 39 times

0

I need to search a word in an interval in the sentence. Example the sentence below:

HTML was created in 1991 by Tim Berners-Lee at CERN (European Council for Nuclear Research) in Switzerland. Initially HTML was designed to interconnect nearby research institutions, and sharing documents with ease. In 1992, the library ACPU WWW development ( World Wide Web), a network of global reach, which together with HTML has provided scale use web world.

Always in this text I will separate in a variable the word that is between library and development that in this unique and specific case ACPU. I’ll always have the same text, but the word in the interval will always be different.

  • what you want to research exactly?

  • He was confused, because "everything" in the img source is != of "a word" which is also != a string like: "power-pop.jpg"

  • Actually you just want to take the name of the file?

1 answer

1

Try to use the preg_match. See the example below:

<?php 
    $str = 'O HTML foi criado em 1991, por Tim Berners-Lee, no CERN (European Council for Nuclear Research) na suíça. Inicialmente o HTML foi projetado para interligar instituições de pesquisa próximas, e compartilhar documentos com facilidade. Em 1992, foi liberada a biblioteca ACPU desenvolvimento WWW ( World Wide Web), uma rede de alcance mundial, que junto com o HTML proporcionou o uso em escala mundial da WEB.';
    $term1 = 'biblioteca';
    $term2 = 'desenvolvimento';

    preg_match('/'.preg_quote($term1).'(.*?)'.preg_quote($term2).'/is', $str, $match);
    echo $match[1];
?>

Browser other questions tagged

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