2014-11-17 2 views
0

Я хочу, чтобы добавить пробел между каждым символом пунктуации и маркером, так что текст выглядит следующим образом:Как добавить пробел между пунктуацией и токенами в PHP?

" in dreams " might keep you awake at night , but not because of its creepy imagery , bizarre visual style or story about a clairvoyant madman who lures young girls to their untimely deaths . 
no , the source of potential sleeplessness here lies within the movie's brutally squandered potential , the least of which is an admittedly nifty premise - even by tired serial killer genre standards . 
the big letdown , however , comes upon the realization that this 100-minute head-scratcher was masterminded by neil jordan , the man behind " the crying game . " 
he's no stranger to cinematic weirdness , but this nutty nonsense really pushes the envelope . 
things start out strong enough , with cinematographer darius khondji's stunning camera work guiding viewers into the bowels of a underwater ghost town during a creepy prologue that establishes a notably grim tone right off the bat . 
this eerie opulence remains a dazzling display of showmanship throughout the entire film - there's even something macabre about the way khondji photographs a rustic , seemingly innocent new england autumn - but if there ever was a film that didn't deserve so good a polish , it's this one . 

Обратите внимание, что строка ввода может быть, например, «Это простое - просто Программа PHP! Не так ли? "

Вывод должен быть: «Это просто - просто P H P Программа ISN 'т это...!?»

Знаки препинания в этом случае все, что не является буква или цифра.

+2

Что вы считаете токеном? – DanielGibbs

+0

Какая строка ввода? – jmleroux

+0

Что для вас обозначает символ пунктуации? – Toto

ответ

0

Я предлагаю не использовать «голодный» движок регулярных выражений в вашем случае, просто строка замены будет делать работу:

<?php 
$input_string = "bla bla,bla.another bla;"; 
//you can extend this array as you wish 
$punctoations = array(".",",",":",";"); 
//your replacements, same order as above array  
$replacements = array (" . "," , "," : "," ; "); 
echo str_replace($punctoations, $replacements, $input_string); 
?> 

Посмотрите, как подробнее в PHP documentation.