Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/05/2008, 14:05
anibal_cdf
 
Fecha de Ingreso: marzo-2007
Mensajes: 180
Antigüedad: 19 años, 7 meses
Puntos: 0
correr javascript desde un php , se puede ?

Buenas como andan ?
Les queria consultar lo siguiente.
Tengo un html, con 2 javascripts, lo que hace el html es traducir lo que esta escrito en el box "Type your text here" , lo traduce a idioma sanskrito en el box "See your results here" , y en el box de abajo que dice "Equivalent HTML text" pone los codigos html.


Lo que yo quiero es en un php teniedo una variable con el texto, ejecutar la funcion de javascript y que me devuelva a otra variable el codigo ese de html.

Esto lo hago de php porque tengo un archivo de texto muy grande (mas de 30mb) que estoy haciendole varias conversiones y algunas palabras tiene que traducirse con esto.

aca les copio los codigos y mas abajo pongo un link para que lo vean funcionando

HTML:
Código PHP:

<html>

<
head>
  <
meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
  <
link rel='stylesheet' type='text/css' href='languages.css' />
  <
title>Romanized latin to Sanskrit
  
</title>
  <
script type='text/javascript' src='sanskrit.js'>
    
  
</script>
  <script src='converter.js' type='text/javascript'>
    
  </script>
</head>
<body>
  <h2>Transliterate to Sanskrit
  </h2>
<form name='convarea' action=''>
  <table>
    <tr>
      <th>
        Type your text here
      </th>
      <th>
        See your results here
      </th>
    </tr>
    <tr>
      <td>
        <textarea name='many_words_text' rows='10' cols='40' onfocus='javascript:print_many_words()' onkeyup='javascript:print_many_words()'>romanalipyAH devanAgarIlipyAm parivartanam
        </textarea>
      </td>
      <td>
        <textarea name='converted_text' cols='40' rows='7' class="big">
          
        </textarea>
      </td>
    </tr>
    <tr>
      <th colspan='2'>
        Equivalent HTML text
      </th>
    </tr>
    <tr>
      <td colspan='2'>
        <textarea name='html_text' rows='5' cols='80' readonly='readonly'>
          
        </textarea>
      </td>
    </tr>
  </table>
</form>
  <table>
  <tr>
    <td>
      <table>
        <tr>
          <td>
<table border='1'>
  <tr>
    <th colspan='12'>Vowels
    </th>
  </tr>
  <tr>
    <td class='mg'>अ
    </td>
    <td>a
    </td>
    <td class='mg'>आ
    </td>
    <td>A
    </td>
    <td class='mg'>इ
    </td>
    <td>i
    </td>
    <td class='mg'>ई
    </td>
    <td>I
    </td>
    <td class='mg'>उ
    </td>
    <td>u
    </td>
    <td class='mg'>ऊ
    </td>
    <td>U
    </td>
  </tr>
  <tr>
    <td class='mg'>ऋ
    </td>
    <td>R
    </td>
    <td class='mg'>&#2316
    </td>
    <td>lR
    </td>
    <td class='mg'>ए
    </td>
    <td>e
    </td>
    <td class='mg'>ऐ
    </td>
    <td>ai
    </td>
    <td class='mg'>ओ
    </td>
    <td>o
    </td>
    <td class='mg'>औ
    </td>
    <td>au
    </td>
  </tr>
</table>
          </td>
        </tr>
        <tr>
          <td>
<table border='1'>
  <tr>
    <th colspan='10'>Specials
    </th>
  </tr>
  <tr>
    <td class='mg'>ः
    </td>
    <td>H, :
    </td>
    <td class='mg'>ं
    </td>
    <td>M
    </td>
    <td class='mg'>।
    </td>
    <td>|
    </td>
    <td class='mg'>॥
    </td>
    <td>||
    </td>
    <td class='mg'>ॐ
    </td>
    <td>oM
    </td>
  </tr>
</table>
          </td>
        </tr>
      </table>
    </td>
    <td>
<table border='1'>
  <tr>
    <th colspan='10'>Consonants
    </th>
  </tr>
  <tr>
    <td class='mg'>क्
    </td>
    <td>k
    </td>
    <td class='mg'>ख्
    </td>
    <td>kh
    </td>
    <td class='mg'>ग्
    </td>
    <td>g
    </td>
    <td class='mg'>घ्
    </td>
    <td>gh
    </td>
    <td class='mg'>ङ्
    </td>
    <td>G
    </td>
  </tr>
  <tr>
    <td class='mg'>च्
    </td>
    <td>c
    </td>
    <td class='mg'>छ्
    </td>
    <td>C
    </td>
    <td class='mg'>ज्
    </td>
    <td>j
    </td>
    <td class='mg'>झ्
    </td>
    <td>jh
    </td>
    <td class='mg'>ञ्
    </td>
    <td>J
    </td>
  </tr>
  <tr>
    <td class='mg'>ट्
    </td>
    <td>T
    </td>
    <td class='mg'>ठ्
    </td>
    <td>Th
    </td>
    <td class='mg'>ड्
    </td>
    <td>D
    </td>
    <td class='mg'>ढ्
    </td>
    <td>Dh
    </td>
    <td class='mg'>ण्
    </td>
    <td>N
    </td>
  </tr>
  <tr>
    <td class='mg'>त्
    </td>
    <td>t
    </td>
    <td class='mg'>थ्
    </td>
    <td>th
    </td>
    <td class='mg'>द्
    </td>
    <td>d
    </td>
    <td class='mg'>ध्
    </td>
    <td>dh
    </td>
    <td class='mg'>न्
    </td>
    <td>n
    </td>
  </tr>
  <tr>
    <td class='mg'>प्
    </td>
    <td>p
    </td>
    <td class='mg'>फ्
    </td>
    <td>ph
    </td>
    <td class='mg'>ब्
    </td>
    <td>b
    </td>
    <td class='mg'>भ्
    </td>
    <td>bh
    </td>
    <td class='mg'>म्
    </td>
    <td>m
    </td>
  </tr>
  <tr>
    <td class='mg'>य्
    </td>
    <td>y
    </td>
    <td class='mg'>र्
    </td>
    <td>r
    </td>
    <td class='mg'>ल्
    </td>
    <td>l
    </td>
    <td class='mg'>व्
    </td>
    <td>v
    </td>
    <td class='mg'>श्
    </td>
    <td>z
    </td>
  </tr>
  <tr>
    <td class='mg'>ष्
    </td>
    <td>S
    </td>
    <td class='mg'>स्
    </td>
    <td>s
    </td>
    <td class='mg'>ह्
    </td>
    <td>h
    </td>
  </tr>
</table>
    </td>
  </tr>
</table>
</body>
</html> 
sanskrit.js
Código PHP:
// This file is part of Indian Language Converter

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" : "&#2316",
"~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" : "ॐ",
"*" : "्"
} 
converter.js
Código PHP:

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(index_pmw)
{
  var 
text_pmw = many_words(document.convarea.many_words_text.value);

  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 = "";
    }
  }

  
document.convarea.converted_text.value = ans;

  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 + ";";
    }
  }

  
document.convarea.html_text.value = html_txt;
}