Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Monday, September 26, 2011

PHP explode function on array

Today while working on the project of PHP-Reportica , I felt need of  applying php explode function on some php variable. Though usage of explode function was bit easy and I already used it, but this time I need to use it in much complicated way.

I was having a field with value of  selected_table_name.select_field_name. Now I had easily separated these two using function as:-

$explode_data= explode(".",  $tab_field);

Two arrays are formed now viz.  $explode_data[0] and $explode_data[1]. But issue was that first array might have redundant entries of same table names. Now, I stuck at this point, How to do it???

I find solution after about one hour spending one this thing. I came to know about a PHP function called unique array which removes redundant entries from an array.  Here below is what I needed:-
 foreach ($_POST['selfield'] as $mystring) {
$rs=explode(",",$mystring);
$first[]= $rs[0];
}
$uniqtab= array_unique($first);
$count= count($uniqtab);
$i=0;
foreach ($uniqtab as $table){
    echo $table;
     if ($i < ($count - 1)) {
      echo ', ';
   }
   $i=$i+1;
}

Thursday, July 29, 2010

Designing Graphics in LaTeX through Web

Today I started another topic of my project. Although the training is over now but the task regarding project is still pending. To design Graphics in LaTeX i need a script that run latex compiling commands from web browser and a php code that calls the script and last a .tex file to be compiled containing graphics code.

For the script that run latex commands do following:
Got to terminal
$cd /var/www/
$sudo mkdir demo
$cat > script.bat
cd /var/www/demo
latex slide.tex
dvips slide -o
ps2pdf slide.ps
^z
Now to design the php code that runs the script:
Go to terminal again
$cd /var/www/demo
$sudo -s
#vi index.php
$command = "sh script.bat";
exec($command, $output=array());
?>
:wq!
#exit
Now give the permissions to whole demo folder so that script can create some other files during latex file compilation without any difficulty.