programing

php, 특수문자를 텍스트로 변환하는 방법은?

bestprogram 2023. 10. 19. 22:38

php, 특수문자를 텍스트로 변환하는 방법은?

xxxi 가 가지고 있습니다the_title()이 경우에는 텍스트를 반환합니다.Blue & Whiny

우리가 알 수 있듯이 문제는 & 캐릭터가 다르게 보인다는 것입니다.

어떻게 돌까요?Blue & Whiny안으로Blue & Whiny시도했습니다:htmlspecialchars_decode(the_title()),html_entity_decode(the_title()),htmlspecialchars(the_title())그리고 아무것도.

나는 전환하고 싶습니다.&로.&

공유할 코드가 많지 않습니다. 그냥 이렇게 하죠.<?php the_title() ?>나는 이해합니다.Blue &#038; Whiny. 사용하는 경우get_the_title()아무것도 표시하지 않습니다.

무슨 생각 있어요?감사해요.

edit1. 일부 코드를 공유합니다.

<script type="text/javascript">
function showShareUI() {

var act = new gigya.services.socialize.UserAction();
act.setUserMessage("Check out this article.");
act.setTitle("Trends on Explore Talent - <?php  the_title(); ?>");
act.setDescription("<?php  get_the_content();  ?>");
act.setLinkBack("<?php  the_permalink();  ?>");
act.addActionLink("Check out this article", "<?php the_permalink(); ?>");

var image = {
src: 'http://xxx.com/wp-content/uploads/2011/05/BOTTOM_BANNER.jpg',
href: '<?php the_permalink();?>',
type: 'image'
}
act.addMediaItem(image);

var params = 
{
userAction: act,  // The UserAction object enfolding the newsfeed data.                                           
onError: onError,  // onError method will be summoned if an error occurs. 
onSendDone: onSendDone // onError method will be summoned after 
,showEmailButton: true
    // Gigya finishes the publishing process.
};

gigya.services.socialize.showShareUI(conf, params);
}

function onError(event) {
alert('An error has occured' + ': ' + event.errorCode + '; ' + event.errorMessage);
}

function onSendDone(event)
{
document.getElementById('status').style.color = "green";
document.getElementById('status').innerHTML = 'The newsfeed has been posted to: ' +     event.providers;
}
</script>

나는 모든 걸 시도 했다.이게 나를 짜증나게 하기 시작했어요...

html_entity_decode() 올바른 방법입니다.

html_entity_decode("Blue &#038; Whiny");

생산 예정:

블루앤휘니

작동하지 않는 경우 이중 인코딩된 문자열을 전달하거나 실행하는 등의 다른 문제가 없는지 확인합니다.htmlentities()나중에 다시 현에.

데모: http://codepad.org/BHXGWXJi

리터럴 문자열로 두 번 확인하고var_dump()출력 결과, 디코딩된 버전을 봐야 합니다.그리고나서var_dump(the_title()), 당신이 생각하는 것을 실제로 통과하고 있는지 확인하기 위해서입니다.html_entity_decode().

html_entity_decode가 트릭을 수행해야 합니다.그렇지 않은 경우 세 번째 매개 변수를 지정합니다.$charset.

다음과 같은 경우:

echo html_entity_decode(the_title(), ENT_QUOTES, 'UTF-8');

the_title() 제목을 직접 인쇄하므로 추가합니다.html_entity_decode()효과가 없을 겁니다그러나 세 번째 함수 인수를 사용하여 인쇄를 중지할 수 있습니다.예.

<?php echo html_entity_decode(the_title('', '', false)) ?>

제목을 직접 인쇄하지는 않지만, 제목을 원하는 게시물의 ID가 필요하며, 이는 대조적입니다.the_title, 현재 게시물의 제목을 루프에 인쇄합니다.그래서 당신은 다음과 같은 것을 할 필요가 있습니다.

<?php echo html_entity_decode(get_the_title($post->ID)) ?>

그리고 실제로 다음과 같은 작업을 수행할 수 있어야 합니다.

<?php echo $post->post_title ?>

이러한 유틸리티 기능이 존재하는 유일한 이유는 사용자를 위해 물건을 탈출하고 태그 등을 추가하는 것입니다.원입력만 원하신다면 직접 출력하시면 됩니다.

그러나 이렇게 해서 자바스크립트 문자열 안에서 반향을 일으키기 때문에 특정 문자에서 벗어날 필요가 있기 때문에 모든 문제가 해결되지는 않습니다.json_encode() 이 방법을 사용해야 하지만 자세한 내용은 "PHP 문자열을 자바스크립트 변수에 전달(새탈출 포함)"이라는 질문을 참조하십시오.

시도해 보기:

echo(mb_convert_encoding(the_title(), "UTF-8", "HTML-ENTITIES"));

이것이 당신에게 적합한지 확인해보세요.

$convmap = array (0x0, 0xffff, 0, 0xffff);
//$str = mb_decode_numericentity (the_title(), $convmap, 'UTF-8' );
$str = mb_decode_numericentity ("&#038;", $convmap, 'UTF-8' );
echo $str;

http://www.php.net/manual/en/function.mb-decode-numericentity.php

언급URL : https://stackoverflow.com/questions/6683826/php-how-to-convert-special-characters-to-text