php 코드의 섹션을 str_replace하는 방법
-
20-09-2019 - |
문제
$embedCode = <<<EOF
getApplicationContent('video','player',array('id' => $iFileId, 'user' => $this->iViewer, 'password' => clear_xss($_COOKIE['memberPassword'])),true)
EOF;
$name = str_replace($embedCode,"test",$content);
코드 섹션을 다른 코드로 바꾸려고합니다. 작은 문자열로 할 수 있지만 더 큰 문자열을 $ embedcode에 추가하면 "예기치 않은 t_encapsed_and_whitespace"오류를 던지기
해결책
당신은 에스케이프해야합니다 $
사용 \$
$embedCode = <<<EOF
getApplicationContent('video','player',array('id' => \$iFileId, 'user' => \$this->iViewer, 'password' => clear_xss(\$_COOKIE['memberPassword'])),true)
EOF;
목표가 Vars 이름을 사용하는 것이라면 변수의 실제 값을 사용하려면 문제가 $ this-> iviewer ...
다른 팁
$ _cookie 근처의 Memberpassword 주위를 제거하십시오
어쨌든 내부의 변수를 해석하지 않는 언어 구성을 찾고있는 것 같습니다. 따라서 Heredoc 구문이 아닌 정기적 인 문자열 정의를 사용해야합니다.
$sample = 'qwe $asd zxc';
또는 marcx가 제안한대로 와 함께 $ $를 탈출하십시오
제휴하지 않습니다 StackOverflow