{"id":511,"date":"2018-01-12T07:58:07","date_gmt":"2018-01-12T07:58:07","guid":{"rendered":"http:\/\/www.cotocus.com\/blog\/?p=511"},"modified":"2018-01-12T08:16:30","modified_gmt":"2018-01-12T08:16:30","slug":"how-to-add-live-search-functionality-to-your-website","status":"publish","type":"post","link":"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/","title":{"rendered":"How to add live search functionality to your website?"},"content":{"rendered":"<p>With Php Custom Search, full-featured text search engine library written entirely in Php,javascript and xml. It is a technology suitable for nearly any application that requires full-text search.<\/p>\n<p><strong>step-1<\/strong> First you create index.html page and adding some javascript code for using functionality livesearch.php page<br \/>\n<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;script&gt;\r\nfunction showResult(str) {\r\n  if (str.length==0) { \r\n    document.getElementById(&quot;livesearch&quot;).innerHTML=&quot;&quot;;\r\n    document.getElementById(&quot;livesearch&quot;).style.border=&quot;0px&quot;;\r\n    return;\r\n  }\r\n  if (window.XMLHttpRequest) {\r\n    \/\/ code for IE7+, Firefox, Chrome, Opera, Safari\r\n    xmlhttp=new XMLHttpRequest();\r\n  } else {  \/\/ code for IE6, IE5\r\n    xmlhttp=new ActiveXObject(&quot;Microsoft.XMLHTTP&quot;);\r\n  }\r\n  xmlhttp.onreadystatechange=function() {\r\n    if (this.readyState==4 &amp;&amp; this.status==200) {\r\n      document.getElementById(&quot;livesearch&quot;).innerHTML=this.responseText;\r\n      document.getElementById(&quot;livesearch&quot;).style.border=&quot;1px solid #A5ACB2&quot;;\r\n    }\r\n  }\r\n  xmlhttp.open(&quot;GET&quot;,&quot;livesearch.php?q=&quot;+str,true);\r\n  xmlhttp.send();\r\n}\r\n&lt;\/script&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n\r\n&lt;form&gt;\r\n&lt;input type=&quot;text&quot; size=&quot;30&quot; onkeyup=&quot;showResult(this.value)&quot;&gt;\r\n&lt;div id=&quot;livesearch&quot;&gt;&lt;\/div&gt;\r\n&lt;\/form&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p>\n<strong>step-2<\/strong> Then you create livesearch.php page <\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php\r\n$xmlDoc = new DOMDocument();\r\n$xmlDoc-&gt;load(&quot;links.xml&quot;);\r\n$x=$xmlDoc-&gt;getElementsByTagName('link');\r\n$q=$_GET&#x5B;&quot;q&quot;];\r\nif(strlen($q)&gt;0)\r\n{\r\n\t$hint=&quot;&quot;;\r\n\tfor($i=0;$i&lt;($x-&gt;length);$i++)\r\n\t{\r\n\t\t$y=$x-&gt;item($i)-&gt;getElementsByTagName('title');\r\n\t\t$z=$x-&gt;item($i)-&gt;getElementsByTagName('url');\r\n\t\tif($y-&gt;item(0)-&gt;nodeType==1)\r\n\t\t{\r\n\t\t\tif(stristr($y-&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue,$q))\r\n\t\t\t{\r\n\t\t\t\tif($hint=&quot;&quot;)\r\n\t\t\t\t{\r\n\t\t\t\t\t$hint=&quot;&lt;a href='&quot; .\r\n\t\t\t\t\t$z-&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue. \r\n\t\t\t\t\t&quot;' target='_blank'&gt;&quot; . \r\n\t\t\t\t\t$y-&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue.&quot;&lt;\/a&gt;&quot;;\r\n\t\t\t\t}\r\n\t\t\t\telse\r\n\t\t\t\t{\r\n\t\t\t\t\t$hint=$hint . &quot;&lt;br\/&gt;&lt;a href='&quot; .\r\n\t\t\t\t\t$z-&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue .\r\n\t\t\t\t\t&quot;' target='_blank'&gt;&quot;.\r\n\t\t\t\t\t$y-&gt;item(0)-&gt;childNodes-&gt;item(0)-&gt;nodeValue. &quot;&lt;\/a&gt;&quot;;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\nif($hint==&quot;&quot;){\r\n\t$response = &quot;No results found&quot;;\r\n}\r\nelse\r\n{\r\n\t$response = $hint;\r\n}\r\necho $response;\r\n?&gt;\r\n<\/pre>\n<p>\n<strong>step-3<\/strong> Then you create links.xml file links.xml is used for linking with search data.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;pages&gt;\r\n&lt;link&gt;\r\n&lt;title&gt;HTML br tag&lt;\/title&gt;\r\n&lt;url&gt;https:\/\/www.w3schools.com\/tags\/tag_br.asp&lt;\/url&gt;\r\n&lt;\/link&gt;\r\n&lt;link&gt;\r\n&lt;title&gt;CSS background Property&lt;\/title&gt;\r\n&lt;url&gt;\r\nhttps:\/\/www.w3schools.com\/cssref\/css3_pr_background.asp\r\n&lt;\/url&gt;\r\n&lt;\/link&gt;\r\n&lt;link&gt;\r\n&lt;title&gt;CSS border Property&lt;\/title&gt;\r\n&lt;url&gt;https:\/\/www.w3schools.com\/cssref\/pr_border.asp&lt;\/url&gt;\r\n&lt;\/link&gt;\r\n&lt;link&gt;\r\n&lt;title&gt;JavaScript Date Object&lt;\/title&gt;\r\n&lt;url&gt;https:\/\/www.w3schools.com\/jsref\/jsref_obj_date.asp&lt;\/url&gt;\r\n&lt;\/link&gt;\r\n&lt;link&gt;\r\n&lt;title&gt;JavaScript Array Object&lt;\/title&gt;\r\n&lt;url&gt;\r\nhttps:\/\/www.w3schools.com\/jsref\/jsref_obj_array.asp\r\n&lt;\/url&gt;\r\n&lt;\/link&gt;\r\n&lt;\/pages&gt;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>With Php Custom Search, full-featured text search engine library written entirely in Php,javascript and xml. It is a technology suitable for nearly any application that <a class=\"mh-excerpt-more\" href=\"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/\" title=\"How to add live search functionality to your website?\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":14,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[203],"tags":[208,186],"class_list":["post-511","post","type-post","status-publish","format-standard","hentry","category-php","tag-php","tag-search"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to add live search functionality to your website? - Cotocus<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to add live search functionality to your website? - Cotocus\" \/>\n<meta property=\"og:description\" content=\"With Php Custom Search, full-featured text search engine library written entirely in Php,javascript and xml. It is a technology suitable for nearly any application that [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/\" \/>\n<meta property=\"og:site_name\" content=\"Cotocus\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-12T07:58:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-12T08:16:30+00:00\" \/>\n<meta name=\"author\" content=\"ashwani Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"ashwani Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/\"},\"author\":{\"name\":\"ashwani Kumar\",\"@id\":\"https:\/\/www.cotocus.com\/blog\/#\/schema\/person\/301c405ff2c201a381ea126a3698a888\"},\"headline\":\"How to add live search functionality to your website?\",\"datePublished\":\"2018-01-12T07:58:07+00:00\",\"dateModified\":\"2018-01-12T08:16:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/\"},\"wordCount\":578,\"keywords\":[\"php\",\"search\"],\"articleSection\":[\"Php\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/\",\"url\":\"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/\",\"name\":\"How to add live search functionality to your website? - Cotocus\",\"isPartOf\":{\"@id\":\"https:\/\/www.cotocus.com\/blog\/#website\"},\"datePublished\":\"2018-01-12T07:58:07+00:00\",\"dateModified\":\"2018-01-12T08:16:30+00:00\",\"author\":{\"@id\":\"https:\/\/www.cotocus.com\/blog\/#\/schema\/person\/301c405ff2c201a381ea126a3698a888\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.cotocus.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to add live search functionality to your website?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.cotocus.com\/blog\/#website\",\"url\":\"https:\/\/www.cotocus.com\/blog\/\",\"name\":\"Cotocus\",\"description\":\"Shaping Tomorrow\u2019s Tech Today\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.cotocus.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.cotocus.com\/blog\/#\/schema\/person\/301c405ff2c201a381ea126a3698a888\",\"name\":\"ashwani Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.cotocus.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a3242d067120cf1862729f6a97db1450cae84ae1186e6adc0736f49282630d21?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a3242d067120cf1862729f6a97db1450cae84ae1186e6adc0736f49282630d21?s=96&d=mm&r=g\",\"caption\":\"ashwani Kumar\"},\"url\":\"https:\/\/www.cotocus.com\/blog\/author\/ashwani\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to add live search functionality to your website? - Cotocus","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/","og_locale":"en_US","og_type":"article","og_title":"How to add live search functionality to your website? - Cotocus","og_description":"With Php Custom Search, full-featured text search engine library written entirely in Php,javascript and xml. It is a technology suitable for nearly any application that [...]","og_url":"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/","og_site_name":"Cotocus","article_published_time":"2018-01-12T07:58:07+00:00","article_modified_time":"2018-01-12T08:16:30+00:00","author":"ashwani Kumar","twitter_card":"summary_large_image","twitter_misc":{"Written by":"ashwani Kumar","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/#article","isPartOf":{"@id":"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/"},"author":{"name":"ashwani Kumar","@id":"https:\/\/www.cotocus.com\/blog\/#\/schema\/person\/301c405ff2c201a381ea126a3698a888"},"headline":"How to add live search functionality to your website?","datePublished":"2018-01-12T07:58:07+00:00","dateModified":"2018-01-12T08:16:30+00:00","mainEntityOfPage":{"@id":"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/"},"wordCount":578,"keywords":["php","search"],"articleSection":["Php"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/","url":"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/","name":"How to add live search functionality to your website? - Cotocus","isPartOf":{"@id":"https:\/\/www.cotocus.com\/blog\/#website"},"datePublished":"2018-01-12T07:58:07+00:00","dateModified":"2018-01-12T08:16:30+00:00","author":{"@id":"https:\/\/www.cotocus.com\/blog\/#\/schema\/person\/301c405ff2c201a381ea126a3698a888"},"breadcrumb":{"@id":"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.cotocus.com\/blog\/how-to-add-live-search-functionality-to-your-website\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.cotocus.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to add live search functionality to your website?"}]},{"@type":"WebSite","@id":"https:\/\/www.cotocus.com\/blog\/#website","url":"https:\/\/www.cotocus.com\/blog\/","name":"Cotocus","description":"Shaping Tomorrow\u2019s Tech Today","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.cotocus.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.cotocus.com\/blog\/#\/schema\/person\/301c405ff2c201a381ea126a3698a888","name":"ashwani Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.cotocus.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a3242d067120cf1862729f6a97db1450cae84ae1186e6adc0736f49282630d21?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a3242d067120cf1862729f6a97db1450cae84ae1186e6adc0736f49282630d21?s=96&d=mm&r=g","caption":"ashwani Kumar"},"url":"https:\/\/www.cotocus.com\/blog\/author\/ashwani\/"}]}},"_links":{"self":[{"href":"https:\/\/www.cotocus.com\/blog\/wp-json\/wp\/v2\/posts\/511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cotocus.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cotocus.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cotocus.com\/blog\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cotocus.com\/blog\/wp-json\/wp\/v2\/comments?post=511"}],"version-history":[{"count":8,"href":"https:\/\/www.cotocus.com\/blog\/wp-json\/wp\/v2\/posts\/511\/revisions"}],"predecessor-version":[{"id":1373,"href":"https:\/\/www.cotocus.com\/blog\/wp-json\/wp\/v2\/posts\/511\/revisions\/1373"}],"wp:attachment":[{"href":"https:\/\/www.cotocus.com\/blog\/wp-json\/wp\/v2\/media?parent=511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cotocus.com\/blog\/wp-json\/wp\/v2\/categories?post=511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cotocus.com\/blog\/wp-json\/wp\/v2\/tags?post=511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}