How to remove specific characters/words from a string in PHP?

Member

beatrice.lesch

by beatrice.lesch , in category: PHP , a month ago

How to remove specific characters/words from a string in PHP?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by viviane , a month ago

@beatrice.lesch How about using str_replace function in PHP and replace specific words/characters with empty string? Below is my code example:


1
2
3
4
5
6
<?php

$text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.';

// ipsum  sit amet consectetur adipiscing elit.
echo str_replace(['Lorem', 'dolor', ','], '', $text);