Is there any function to do this in PHP?

Is there any function to do this in PHP?

If I want to get only text but not any other characters from the string say,
Hello, This is a text !
But, How to get plain text |||| from this string?

I want to get from above is,
Hello This is a text
But How to get plain text from this string

Thanks in advance…
:slight_smile:

If I understand you correctly, you want to remove everything from the string except for standard characters from the basic Latin alphabet. Is this correct?

If so, you can do this:

<?php
	$string = 'Hello, This is a text !';
	$plainText = preg_replace('/[^a-z\\s]/i', '', $string);
	echo $plainText;	//Prints "Hello This is a text "
?>

This will remove everything except for alphabetical characters and whitespace. If you want to allow digits as well, you can replace the third line with this:

	$plainText = preg_replace('/[^a-z0-9\\s]/i', '', $string);

Also note that in the example you gave (i.e. “Hello, This is a text !”), you will end up with a space after “text”. If you want to remove the extra whitespace from both sides, you can use this:

	$plainText = trim(preg_replace('/[^a-z\\s]/i', '', $string));