I have an incoming string to be saved to the database, let’s say it’s:
She said, “I am going to London.”
There are different kinds of double quotes, apostrophes, commas, maybe even different kinds of full stops, so I think it is easiest it I just get rid of all punctuation and just leave the words, separated by a space. (I’ll do the same with the answer key.)
I think for this job PHP str_contains(string $haystack
, string $needle
): bool may be good, but I’d have to know all possible types of punctuation and have them in an array.
Maybe better with: ctype_alpha(
$string
[
$i
]) ), here I only want (English) alphabetical characters.
for
(
$i
= 0;
$i
<
$length
;
$i
++) {
if
(! ctype_alpha(
$string
[
$i
]) ) {
delete the character
;`
}
Anyway, I need to put together a function to check strings and remove punctuation, say
function sanitizeStrings($string) {
Can you help me please?