Tengo una funcion que esta hecha en javascript, pero la necesito usar en php , alguno sabria hacer como una copia pero en php ? porque no entiendo ni como funcionan las funciones nativas de js.
Código PHP:
var vowels = "(A)|(H)|(I)|(M)|(R)|(U)|(\\:)|(\\|(\\|)?)|(a((i)|(u))?)|(e)|(i)|(lR)|(o(M)?)|(u)"
var consonants = "(C)|(D(h)?)|(G)|(J)|(N)|(S)|(T(h)?)|(b(h)?)|(c)|(d(h)?)|(g(h)?)|(h)|(j(h)?)|(k(h)?)|(l)|(m)|(n)|(p(h)?)|(r)|(s)|(t(h)?)|(v)|(y)|(z)"
var letter_codes = {
"~a" : "अ",
"~A" : "आ",
"~i" : "इ",
"~I" : "ई",
"~u" : "उ",
"~U" : "ऊ",
"~R" : "ऋ",
"~lR" : "ऌ",
"~e" : "ए",
"~ai" : "ऐ",
"~o" : "ओ",
"~au" : "औ",
"a" : "",
"A" : "ा",
"i" : "ि",
"I" : "ी",
"u" : "ु",
"U" : "ू",
"R" : "ृ",
"lR" : "ॄ",
"e" : "े",
"ai" : "ै",
"o" : "ो",
"au" : "ौ",
"k" : "क",
"kh" : "ख",
"g" : "ग",
"gh" : "घ",
"G" : "ङ",
"c" : "च",
"C" : "छ",
"j" : "ज",
"jh" : "झ",
"J" : "ञ",
"T" : "ट",
"Th" : "ठ",
"D" : "ड",
"Dh" : "ढ",
"N" : "ण",
"t" : "त",
"th" : "थ",
"d" : "द",
"dh" : "ध",
"n" : "न",
"p" : "प",
"ph" : "फ",
"b" : "ब",
"bh" : "भ",
"m" : "म",
"y" : "य",
"r" : "र",
"l" : "ल",
"v" : "व",
"z" : "श",
"S" : "ष",
"s" : "स",
"h" : "ह",
"H" : "ः",
":" : "ः",
"M" : "ं",
"|" : "।",
"||" : "॥",
"oM" : "ॐ",
"~H" : "ः",
"~:" : "ः",
"~M" : "ं",
"~|" : "।",
"~||" : "॥",
"~oM" : "ॐ",
"*" : "्"
}
function split_word(word)
{
var syllables = new Array(0);
var vowel_start_p = true;
while (word.length) {
re = new RegExp(vowels);
var index = word.search(vowels);
if (index == 0) { //the vowel's at the start of word
var matched = re.exec(word)[0]; //what is it?
if (vowel_start_p) {
syllables.push(("~"+matched)); //one more to the syllables
} else {
syllables.push(matched);
}
vowel_start_p = true;
word = word.substring(matched.length);
} else {
re = new RegExp(consonants);
var index = word.search(consonants);
if (index == 0) {
var matched = re.exec(word)[0];
syllables.push(matched);
vowel_start_p = false;
word = word.substring(matched.length);
//look ahead for virama setting
var next = word.search(vowels);
if (next != 0 || word.length == 0)
syllables.push('*');
} else {
syllables.push(word.charAt(0));
word = word.substring(1);
}
}
}
return syllables;
}
function match_code(syllable_mcc)
{
var matched = letter_codes[syllable_mcc];
if (matched != null) return matched;
return syllable_mcc;
}
function one_word(word_ow)
{
if (!word_ow) return "";
var syllables_ow = split_word(word_ow);
var letters_ow = new Array(0);
for (var i_ow = 0; i_ow < syllables_ow.length; i_ow++) {
letters_ow.push(match_code(syllables_ow[i_ow]));
}
return letters_ow.join("");
}
function many_words(sentence)
{
var regex = "((" + vowels + ")|(" + consonants + "))+";
var words = new Array(0);
while (sentence.length >= 1) {
re = new RegExp("^``" + regex);
var match = re.exec(sentence);
if (match != null) {
match = match[0];
words.push("`");
words.push(one_word(match.substring(2)));
sentence = sentence.substring(match.length);
} else {
re = new RegExp("^`" + regex);
match = re.exec(sentence);
if (match != null) {
match = match[0];
words.push(match.substring(1));
sentence = sentence.substring(match.length);
} else {
re = new RegExp("^" + regex);
match = re.exec(sentence);
if (match != null) {
match = match[0];
words.push(one_word(match));
sentence = sentence.substring(match.length);
} else {
words.push(sentence.charAt(0));
sentence = sentence.substring(1);
}
}
}
}
return words.join("");
}
function print_many_words(palabra)
{
var text_pmw = many_words(palabra);
var ans = "";
while (text_pmw.length) {
var unicode_chars = /&#[0-9]+;/;
re = unicode_chars;
var matche = re.exec(text_pmw);
if (matche != null) {
matche = matche[0];
search = text_pmw.search(unicode_chars);
ans += text_pmw.substring(0, search);
ans += String.fromCharCode(matche.match(/[0-9]+/));
text_pmw = text_pmw.substring(search + matche.length);
} else {
ans += text_pmw.substring(0);
text_pmw = "";
}
}
var html_txt = "";
for (i=0; i<ans.length; i++) {
var unicode_character = ans.charCodeAt(i);
switch (unicode_character) {
case 32:
html_txt += " ";
break;
case 10:
case 13:
html_txt += "<br/>\n";
break;
default:
html_txt += "&#" + unicode_character + ";";
}
}
return html_txt;
}