관리 메뉴

웹개발자의 기지개

[PHP] 다량의 문자열내용중에 특정 문자열 교체하기 본문

PHP

[PHP] 다량의 문자열내용중에 특정 문자열 교체하기

http://portfolio.wonpaper.net 2022. 5. 2. 15:18

특정 웹주소로 접근할때에 다량의 문자열내용중 특정문자열을 변경하기

 

코딩작업을 하는 과정에서 잠깐 기록해 본다.

 

/2022/contents/news.php 라는 웹주소가 있을때,

 

1
2
3
4
5
6
7
8
$rURL = explode('/',$_SERVER['REQUEST_URI']);
if ($rURL[1]=="2022") {
    $contents = str_replace("../pack", "../../pack",$contents);
    echo "<br>".$contents."<br><br>";   
    
} else {
    echo "<br>".$contents."<br><br>";   
}
cs

 

../pack 문자열을 ../../pack 문자열로 간단히 문자열 교체를 하고 있다.

str_replace() 함수

 

https://www.php.net/manual/en/function.str-replace.php

 

PHP: str_replace - Manual

<!--?php public static function convert_chars_to_entities( $str ) {     $str = str_replace( 'À', 'À', $str );     $str = str_replace( 'Á', 'Á', $str );     $str = str_replace( 'Â', 'Â', $str );     $str = str_replace( 'Ã', 'Ã', $str );  

www.php.net

 

 

Comments