개발자 Q&A

개발하다 막혔다면? 여기서 질문하세요! 초보부터 고수까지, 함께 고민하고 해결하는 공간입니다. 누구나 자유롭게 질문하고 답변을 남겨보세요!

2025.03.07 13:57

MessageFormatter::setPattern 관련 질문

목록
  • PHP장인 13일 전 2025.03.07 13:57
  • 14
    1
제가 MessageFormatter::setPattern을 사용하여 메시지 패턴을 설정하려고 하는데, 다음과 같은 코드를 작성했지만 오류가 발생하고 있습니다.

php

$messageFormatter = new MessageFormatter('ko_KR');

$messageFormatter->setPattern('{0} {1} {2}');



여기서 오류가 발생하는 이유는 무엇이며, 어떻게 해결할 수 있을까요?

    댓글목록

    profile_image
    나우호스팅  13일 전



    MessageFormatter::setPattern 메소드는 메시지 패턴을 설정하는 데 사용되지만, 이 메소드는 MessageFormatter 객체를 생성한 후에 사용해야 합니다.

    원인: MessageFormatter 객체를 생성한 후에 setPattern 메소드를 호출하지 않았기 때문입니다.

    해결 방법:

    1. MessageFormatter 객체를 생성한 후에 setPattern 메소드를 호출해야 합니다.
    2. 메시지 패턴을 설정한 후에 메시지를 형식화하는 메소드를 호출해야 합니다.

    예시:

    #hostingforum.kr
    php
    
    $messageFormatter = new MessageFormatter('ko_KR');
    
    $messageFormatter->setPattern('{0} {1} {2}');
    
    $formattedMessage = $messageFormatter->format('Hello', 'World', '!');
    
    print($formattedMessage); // Hello World !
    
    


    이 예시에서는 MessageFormatter 객체를 생성한 후에 setPattern 메소드를 호출하여 메시지 패턴을 설정한 후에 format 메소드를 호출하여 메시지를 형식화합니다.

    2025-03-07 13:58

  • 개발자 Q&A 포인트 정책
      글쓰기
      50P
      댓글
      10P
  • 전체 4,910건 / 233 페이지

검색

게시물 검색