▶ trim() : 화이트스페이스를 제거
▶ strlen() : 문자열의 길이를 알려준다.
▶ printf() 이용해 0으로 채우기
1 2 3 4 5 6 | $zip = '6520'; $month = 2; $day = 6; $year = 2007; printf("우편번호는 %05d이고 날짜는 %02d/%02d/%d", $zip, $month, $day, $year); | cs |
결과 : 우편번호는 06520이고 날짜는 02/06/2007
▶ strcasecmp() : 대소문자 관계없이 문자열 비교하기
1 2 3 4 5 6 7 | $string1 = 'aaaaa'; if(strcasecmp($string1, 'AAAAA') == 0){ echo "같다"; }else{ echo "다르다"; } | cs |
▶ strtolower() : 모두소문자로
▶ strtoupper() : 모두대문자로
▶ ucwords(strtolower('JOHN FRANKENHEIMER')); : 앞글자만 대문자로 (John Frankenheimer)
substr() : 문자열 줄이기(원하는 일부만 추출할 수 있다. 문자열 첫 글자부터 시작해30바이트를 추출하라)
1 2 3 4 5 | $_POST['comments'] = "The Fresh Fish with Rice Noodle was delicious, but I didn't"; echo substr($_POST['comments'], 0, 30); echo '...'; | cs |
결과 : The Fresh Fish with Rice Noodl...
▶ str_replace() : 문자열 일부를 치환해준다.
1 2 3 4 5 6 | $html = '<span class="{class}">유부</span> <span class="{class}">생선튀김</span>'; $my_class = 'lunch'; echo str_replace('{class}', $my_class, $html); | cs |
class의 name이 lunch로 치환되었다.
'PHP 코드관련' 카테고리의 다른 글
매월 마지막 날짜 구하기 (0) | 2019.08.12 |
---|---|
문자열 내부에 변수 넣기 (0) | 2019.07.24 |
큰따옴표 문자열 안에서 사용할 수 있는 특수 문자 (0) | 2019.07.23 |
img 주소값에서 이미지만 가져오는 정규표현식 특정디렉터리만 가져오는 방법 (0) | 2019.07.16 |
배열의 필요없는 문자열을 제거하기 (0) | 2019.06.01 |