I have a javascript function designed to search a string returned by a PHP chatbot (response) for a specific value before stopping and then outputting everything that came before it (i.e. say the string was 'Hello how are you' and it was told to look for 'are' then it would output 'Hello how ').
It uses the indexOf function and looks something like this -
Code: Select all
<script>
var response= "' . fixquote($botresponse->response) . '";
var position = 0;
var chat = "";
function Talk()
{
position = response.indexOf("<br>");
if(position > -1)
{
chat = response.substring(0,position);
}
else
{
chat = response;
}
}
Talk();
</script>I need it because certain responses from the chatterbot include JavaScript and break the function above when you nest <script> tags inside each other.
Any help is appreciated. Thanks - Andrew