W3docs

Allow only [a-z][A-Z][0-9] in string using PHP

You can use the preg_replace function in PHP to remove any characters that do not match the specified pattern.

You can use the preg_replace function in PHP to remove any characters that do not match the specified pattern. To allow only lowercase letters, uppercase letters, and digits in a string, you can use the following code:

Example of allowing only [a-z][A-Z][0-9] in string using PHP

<?php

$string = "Hello World! 123";

$string = preg_replace("/[^a-zA-Z0-9]/", "", $string);

echo $string;

// Output:
// HelloWorld123

?>

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

This will remove all characters that are not lowercase letters, uppercase letters, or digits from the $string variable.