Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Ajax
- 전략
- function
- string
- jquery
- composer-php
- 웹하드순위
- HTML
- 경영
- Linux
- php
- Apache
- Session
- post
- MySQL
- OOP
- variables
- file-upload
- curl
- Regex
- Arrays
- Laravel
- date
- 무료다운로드쿠폰
- UTF-8
- JSON
- JavaScript
- Forms
- 웹하드추천
Archives
- Today
- Total
개발! 딱 깔끔하고 센스있게!
PHP 에서 문자열 을 slug 으로 변환 합 니 다. 본문
한 줄 의 텍스트 를 단락 으로 바 꾸 는 가장 좋 은 방법 은 무엇 입 니까?의미:
- alpha allowed, convert to lowercase
- numbers are allowed
- spaces should be eliminated, not converted to dash ("-")
- accented characters replaced by equivalent standard alpha
- no other characters allowed, should be stripped out
나 는 인터넷 에서 많은 코드 를 찾 았 지만, 모두 빈 칸 을 디 폴 트 사이즈 로 바 꾸 는 경향 이 있어 서, 나 는 이렇게 하고 싶 지 않다.
나 도 전환 에 관심 이 있다.
그 중:
- ampersand ("&") should be replaced by the string "and"
그리고 변형, 그 중:
- Don't bother converting accented characters to equivalent standard alpha
대답 하 다.
이것 은 내 가 최초 로 여기에서 찾 은 수 정 된 함수 (http: / cubiq. org / the perfect. php clean url generator) 입 니 다.
'-' 를 구분자 로 전달 할 수 있 습 니 다.
public static function createSlug($str, $delimiter = '-'){ $slug = strtolower(trim(preg_replace('/[\s-]+/', $delimiter, preg_replace('/[^A-Za-z0-9-]+/', $delimiter, preg_replace('/[&]/', 'and', preg_replace('/[\']/', '', iconv('UTF-8', 'ASCII//TRANSLIT', $str))))), $delimiter)); return $slug; }
'개발 스크랩 메모 > PHP' 카테고리의 다른 글
PHP 와 자바 script 사이 에 배열 을 전송 하 는 가장 좋 은 방법 은 [duplicate] 입 니 다. (0) | 2020.12.03 |
---|---|
Phongap 으로 아이 폰 에서 PHP 로 사진 올 리 기 (0) | 2020.12.03 |
AJAX 를 통 해 PHP 류 에서 PHPExcel 로 데 이 터 를 전달 합 니 다. (0) | 2020.12.03 |
Facebook Graph API 에서 사용자 의 이메일 주소 와 성별 을 가 져 오 는 API 호출 은 무엇 입 니까? (0) | 2020.12.03 |
PHP 의 드 롭 다운 상자 에서 선택 한 값 가 져 오기 (0) | 2020.12.03 |
Comments