PHP preg_replace()

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:55 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))

1 개요

PHP preg_replace()
$string = '135.79.246.80';
$pattern = '/(\.\d+)$/';
$replacement = '.x';
echo preg_replace($pattern, $replacement, $string);
# 135.79.246.x
$string = 'April 15, 2003';
$pattern = '/(\w+) (\d+), (\d+)/i';
$replacement = '${1}x,$3';
echo preg_replace($pattern, $replacement, $string);
# Aprilx,2003
$string = 'The quick brown fox jumps over the lazy dog.';
$patterns = ['/quick/','/brown/','/fox/'];
$replacements = ['bear','black','slow'];
echo preg_replace($patterns, $replacements, $string);
# The bear black slow jumps over the lazy dog.

2 같이 보기

3 참고

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}