rockstardub
Programmer
What I want: I want the user to be able to write their text, and when the basic text is requested, it will scatter it with images. I don't want users to write HTML tags like <img src>.
I want the php to count 20 words into the string, then insert an html image tag. I don't want to cut a word in half.
I don't know what to do,
1. if I turn it into an array to enter the string by splicing the array then it takes away formatting.
2. if I str_word_count() then I get the location I need, but have no way of manipulating it.
I think the best way to do it would be to make a loop that counts spaces, something like this...
<?
$text = 'a lot of text here';
$string = '<img src="something.jpg">';
for($i = 0; $i < spaces in the string) {
$i++;
if ($i >= 20) {
insert $string into $text here;
}
}
?>
I want the php to count 20 words into the string, then insert an html image tag. I don't want to cut a word in half.
I don't know what to do,
1. if I turn it into an array to enter the string by splicing the array then it takes away formatting.
2. if I str_word_count() then I get the location I need, but have no way of manipulating it.
I think the best way to do it would be to make a loop that counts spaces, something like this...
<?
$text = 'a lot of text here';
$string = '<img src="something.jpg">';
for($i = 0; $i < spaces in the string) {
$i++;
if ($i >= 20) {
insert $string into $text here;
}
}
?>