Login   Register  
PHP Classes
elePHPant
Icontem

File: grammar_test2_php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mark Headd  >  PHP Grammar  >  grammar_test2_php  >  Download  
File: grammar_test2_php
Role: Example script
Content type: text/plain
Description: Moderately complex grammar example
Class: PHP Grammar
Create speech recognition grammar W3C XML files
Author: By
Last change:
Date: 2004-10-03 20:47
Size: 1,283 bytes
 

Contents

Class file image Download
<?php 

// Set MIME type for XML grammar fomat
header('Content-type: application/grammar+xml');

//Include sub class
require ('createGrammar.php');

// Database access inforation
$host "";
$user "";
$password "";
$database "";

// Make connection to databse
$db mysql_connect($host$user$password);

// Select database, submit query and collect results
mysql_select_db($database);
$query "SELECT ch_name, ch_num FROM radio WHERE type='Country'";
$result mysql_query($query);
$num_results mysql_num_rows($result);
mysql_close($db);

// Instantiate arrays to pass to simpleGram function
$name_array = array();
$channel_array = array();

// Populate arrays with result of database query
for ($i=0$i<$num_results$i++)
{
  
$row mysql_fetch_row($result); 
    
array_push($name_array$row[0]);
    
array_push($channel_array$row[1]);
}

// Create new grammar object
$page = new createGrammar;

// Set rule names for grammar
$page->setRoot("primary");
$page->setRuleID("primary");

// Set slot name for return value
$page->setSlot("first");

// Set language (optional - default is US English)
$page->setLang("es-US");

// Pass channel arrays to simpleGram function
$page->simpleGram($name_array$channel_array);

?>