와 자동 완성은 아래와 같이PHP - PHP와 자바 스크립트
<?php
$file = glob('pages/*');
//var_dump($file);
foreach($file as $value)
{
$output = substr($value, 6, strlen($value) - 6);
//echo($output)."<br>";
}
?>
위의 스크립트는 '페이지에있는 모든 파일을 표시합니다 '폴더 즉, pageone.html, pagetwo.html ....
그런 다음 javascript 파일을 사용하여'page '에 입력 할 때'pageone.html '또는'pageone.html '과 같은 자동 완성 옵션이 표시되어야하는 텍스트 필드를 표시합니다. 'pagetwo.html'등
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
var availableTags = ["
<?php echo $output; ?>"
];
$("#tags").autocomplete({
source: availableTags
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="tags">Tags: </label>
<input id="tags">
</div>
</body>
</html>
위의 PHP 코드를이 js와 결합하여 단일 PHP 파일
과 같이 표시합니다. '$ output'을 js 'availableTags'변수에 포함 시키려고 시도하지만 텍스트 필드에 아무 것도 입력하지 않으면 무슨 일이 일어날 지 모르겠다. js에 임베디드 된 PHP 코드와 관련이 있기 때문에 도움이된다.
은 매력처럼 작동합니다. – AS17