I have got to replace a string with an html string. The string contain a certain keyword ( example: Hebrews, Genesis) and some number with symbol at the back (9:28 or 1:2-3). I want to replace the string with html equivalent from database and put the number within the HTML. .
The final result will be like <a class="class_to_use_here">Hebrews 9:28 </a>
<style>a {border-bottom:1px solid blue}</style>
<?php
$string='check this passage Hebrews 9:28';
$find =$replacement= array();
$bibok=array('Hebrews','Genesis');
foreach($bibok as $bib){
$find[]=$bib;
$replacement[]='<a class="class_to_use_here">'.$bib.' </a>';
}
$result = str_ireplace($find, $replacement, html_entity_decode($string));
echo $result;
?>
NOTE:$bibok is a associative array generated from a database with column .
It works well for to bring <a class="class_to_use_here">Hebrews</a>9:28
. Note the string at the back. I want it inside the html element not outside. And the vary could be 9:28-29 in structure not always 9:28. And the value is dynamic depending on what the user type.
The final result will be like <a class="class_to_use_here">Hebrews 9:28 </a>
I was able to achieve this only <a class="class_to_use_here">Hebrews</a> 9:28
. But, I want the numbers structure inside the html element not outside. I can only use this simple str_ireplace. I will be glad to have preg_replace solution if it can be easily implemented in this case.