반응형
따옴표가 있는 URL을 표시하는 입력 필드
저는 MariaDB 데이터베이스에 위키백과 URL을 저장해야 합니다.
일부 URL에 다음과 같은 따옴표가 포함되어 있는 경우가 있습니다.
https://en.wikipedia.org/wiki/%22Heroes%22
그래서 제가.urlencode()
그것들을 다음과 같이 보관합니다."en.wikipedia.org%2Fwiki%2F%22Heroes%22"
.
URL을 디코딩()하면 내부에 표시됩니다.<input type="text">
모든 %가 없는 필드(그들은 숙련되지 않은 사용자들을 겁먹게 한다), 인용문은 깨집니다.input
가치.
결과를 좀 더 편안하게 보여줄 수 있는 이 방법을 찾았습니다.
$url = 'en.wikipedia.org%2Fwiki%2F%22Heroes%22'; // it comes in this way from the DB
$tmp = str_replace('%22','"', $url);
$url_input = urldecode($tmp);
echo "<input type=\"text\" value=\"$url_input\" />";
의 가치.$url_input
일이 원만히 이루어지다<a href
닻을 내리고, 양식에서 오는 쿼리는 다음으로 필터링됩니다.FILTER_SANITIZE_URL
그리고.urlencode()
DB에 저장할 수 있습니다.
더 좋은 방법이 없을까요?
str_replace() 대신 html specialchars()만 사용합니다.
$url = 'en.wikipedia.org%2Fwiki%2F%22Heroes%22'; // it comes in this way from the DB
//$tmp = str_replace('%22','"', $url);
$url_input = htmlspecialchars(urldecode($url));
echo "<input type=\"text\" value=\"$url_input\" />";
이것보다 더 효과가 좋을 것 같습니다.
언급URL : https://stackoverflow.com/questions/28792001/input-field-showing-an-url-with-quotes
반응형
'sourcecode' 카테고리의 다른 글
테이블 Excel VBA에 새 열 삽입 (0) | 2023.10.20 |
---|---|
PowerShell에서 EXE 출력 캡처 (0) | 2023.10.20 |
쉼표로 구분된 목록 MySQL에서 항목 수를 세는 방법 (0) | 2023.10.20 |
jsch를 통해 실행하면 자바 프로그램과 mariadb 연결이 되지 않습니다. (0) | 2023.10.20 |
SQL에서 출력을 정수로 선택/캐스팅 (0) | 2023.10.20 |