PHP strips in LUA

Asked

Viewed 119 times

1

I want to convert this PHP code into LUA language. The problem is that there is no function stripos which counts the first occurrence of the desired word in LUA.

How can I convert the code below?

<?php
  echo stripos("I love php, I love php too!","PHP");
?>

1 answer

4


To make the search case-insensitive, you can use the function string.lower() to convert the letters to minuscules and search for the first occurrence with the string.find().

function stripos (palheiro, agulha)
    palheiro = string.lower(palheiro)
    agulha = string.lower(agulha)

    if palheiro ~= nil and agulha ~= nil then   
        return (string.find(palheiro, agulha) -1)   
    else  
        return nil   
    end   
end

print(stripos("I love php, I love php too!", "PHP"))  

DEMO

Browser other questions tagged

You are not signed in. Login or sign up in order to post.