Ben sadece bir kelime seçilmiş olur sağlamak için çalışıyorum bu yüzden ancak içerik HTML içeren bir sayfa için içerik ilk sözcüğü bir yayılma eklemek için regex kullanmaya çalışıyorum. Içerik her sayfa için değiştirir.
Şu script:
preg_match('/(<(.*?)>)*/i',$page_content,$matches);
$stripped = substr($page_content,strlen($matches[0]));
preg_match('/\b[a-z]* \b/i',$stripped,$strippedmatch);
echo substr($page_content, 0, strlen($matches[0])).'<span class="h1">'.$strippedmatch[0].'</span>'.substr($stripped, strlen($strippedmatch[0]));
However if the $page_content is
<p><span class="title">This is </span> my title!</p>
Then my regex thinks the first word is "span" and adds the tags around that.
Bunu düzeltmek için herhangi bir yolu var mı? (Ya da bunu yapmak için daha iyi bir yolu).