- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘Other’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I want to color each punctuation on my website automatically.
For example the question mark is automatically red.
I want to enter only the punctuation mark somewhere in a Javascript or PHP and add the color to a class in my css.
Thank you!
Robin Will from Germany.
With php you can use str_replace to find the character you want to replace and replace it with the same character wrapped in a span with a class which you can style in your css.
Here is an example using the content of a post in WordPress.
$content = str_replace('?', '?', get_the_content();
echo $content;
?>
Normally you would just display the content with “ but first we can grab the content data and do some quick swaps inside the string before outputting it. Since this doesn’t use js it will work even if javascript it turned off and the styles are easily editable via css.
Forgot to mentions, you can do this several times in a row:
$content = str_replace('?', '?', get_the_content();
$content = str_replace('!', '?', $content;
$content = str_replace('.', '?', $content;
echo $content;
?>
My php is only so good, I don’t know if there is a faster or more beneficial way of doing it than this.