How can I achieve the below scenario with php?
Case 1
Input : <h2>Test text <img src="./test.png" /></h2>
Output : <span>T</span><h2>est text <img src="./test.png" /></h2>
Case 2
Input : <p>Test text</h2>
Output : <span>T</span><p>est text</p>
Case 3
Input - <h2><img src="./test.png" /> Test text </h2>
Output - <span>T</span><h2><img src="./test.png" /> est text</h2>
In the input html may be there are so many tags will included. I want any of first block holding the html
I have tried below code
<?php
$firstLetter = strip_tags(get_sub_field('text'));
$firstLetter = $firstLetter[0];
?>
<div class="capLetter"><?php echo $firstLetter; ?></div>
<?php echo substr(get_sub_field('text'), 4); ?>
2
Answers
After dogged so many possibilities I created one function with jQuery
Try below code
Previous answer gets the issue if the first element comes the
<img />
tag then it will not works. So I tried to hide the first char with css.Try below code