2014-10-21 5 views
-1

문자열에서 다음 문자를 제거하고 아무 것도 대체하지 않으려 고합니다. 문자를 대체하기 위해 test을 사용했습니다. 파일은 UTF-8 인코딩으로 저장됩니다str_replace가 문자에서 작동하지 않습니다. < , >과 "

<, >, ", '`

을 나는 간단한 않는 str_replace를 사용했지만 어떤 이유로 ' 작품의 제거가 -.. 나머지는 모두 남아

$title = str_replace('"',"test",$title); 
$title = str_replace("'","test",$title); // this one works 
$title = str_replace("<","test",$title); 
$title = str_replace(">","test",$title); 
$title = str_replace("`","test",$title); 

이 문자들을 제거하는 더 좋은 방법이 있습니까?

편집 : 대신 문자 엔티티를 사용하려고 한 여전히 작동하지 않습니다

echo preg_replace("~'|<|>|:~", "",$title); 

을가하지 않는 중요하지만 :

$title = str_replace('"',"test",$title); 
$title = str_replace("'","test",$title); // this one works 
$title = str_replace("<","test",$title); 
$title = str_replace(">","test",$title); 
$title = str_replace("`","test",$title); 
$title = str_replace(html_entity_decode('&gt;', ENT_COMPAT, 'UTF-8'), '', $title); 
$title = str_replace(html_entity_decode('&lt;', ENT_COMPAT, 'UTF-8'), '', $title); 
$title = str_replace(html_entity_decode('&quot;', ENT_COMPAT, 'UTF-8'), '', $title); 
$title = str_replace(html_entity_decode('&grave;', ENT_COMPAT, 'UTF-8'), '', $title); 
+1

fyi를 붙잡지 않을 것입니다 : 여러 개의 바늘을 사용할 수도 있습니다 :'$ title = str_replace (array '' ',' '', '<', '>', '''), 'test', $ title); '문자열을 게시 할 수도 있습니다. – Ghost

+0

문자열을 게시하십시오. 아니면 더 나은,'echo bin2hex ($ title);의 출력을 게시 –

+0

http://stackoverflow.com/questions/3168392/cant-remove-special-characters-with-str-replace에 게시 된 솔루션을 사용해보십시오 – Gudgip

답변

0

내가 대신 preg_replace를 사용하여이 고정 결국 이 게시물 var에 htmlspecialchars를 사용하거나 <>

관련 문제