저는 PHP에서 초보자이며 ">"와 그 뒤의 모든 다른 문자를 문자열로 대체하고자합니다.">"및 특수 문자 뒤의 모든 문자
http://www.example.com/>testmail
저는 PHP에서 초보자이며 ">"와 그 뒤의 모든 다른 문자를 문자열로 대체하고자합니다.">"및 특수 문자 뒤의 모든 문자
http://www.example.com/>testmail
이 트릭
<?php
$string = 'http://www.example.com/>testmail';
$pattern = '/(>(.*?))$/i';
$replacement = 'helloWorld';
echo preg_replace($pattern, $replacement, $string);
preg_replace이다에 대한 더 많은 일을해야한다 http://php.net/manual/en/function.preg-replace.php
트릭을 주셔서 감사합니다 – Arvis
Np, 패턴은 정규식입니다. 여기에 대해 자세히 알 수 있습니다. http://regexr.com/ – Perspective
여기에 표준 문자열 함수를 사용하여 솔루션입니다 :
자료 제공 :
<?php
//init values
$str = 'tag>content';
$strReplace = '[stuff_here]';
//find 0-based index of angle-bracket char from start of string (if any)
$idxPos = strpos($str,'>');
if ($idxPos !== false)
{
//lop off portion to right and append replacement
$str = substr($str,0,$idxPos) . $strReplace;
}
//print result
echo $str . "\n";
?>
출력 :
tag[stuff_here]
이 당신이 원하는 것을 할 수 보이는 : HTTP : // PHP. net/manual/en/function.preg-replace.php 테스트하지는 않았지만'preg_replace ('/>.$/', 'replacement', $ your_string)'해야합니다. – deeenes