Question

I want to detect punctuation (!@#$%^&*()?<>"';:}{][) wherever in a string (front or behind the string)...

$string = "'Hello!'";
$anotherstring = "Hi";

I want it to record the punctuation in $string and echo it with $anotherstring...

Hello
'Hi!'

Actually I am making a spell checker and the problem is that it checks the string with the punctuation.. I want to check it without the punctuation and echo the before punctuation before the suggestions and the after punctuation after the suggestions...

Était-ce utile?

La solution

This maybe a dirty trick :)

$anotherstring = preg_replace('/[a-zA-Z0-9]+/', $anotherstring, $string);

EDIT: You can remove the digits if you don't need them

Autres conseils

Take a look at http://us3.php.net/manual/en/function.strtok.php

You can split based on tokens such as spaces and symbols.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top