What am I needing to do in order to make this work ?

Please advise ?

I am getting the $song_title from another part of my PHP I am just setting it as something in this example in order to post what I thought should work ? any help would be most appreciated

<?php
$output1="PHPMIN=`echo $song_title | cut -d"(" -f2 | cut -d")" -f1 | cut -d":" -f1`";
$output2="PHPSEC=`echo $song_title | cut -d"(" -f2 | cut -d")" -f1 | cut -d":" -f2`";
$output3="TIMING=`echo "$PHPMIN * 60 + $PHPSEC" | bc`";
shell_exec('song_title = " (4:30) "');
shell_exec('$output1');
shell_exec('$output2');
shell_exec('$output3');
echo "<pre>$PHPMIN</pre>";
echo "<pre>$PHPSEC</pre>";
echo "<pre>$TIMING</pre>";

?>

Recommended Answers

All 11 Replies

Could you explain exactly what you are trying to achieve. Perhaps php can do the job without the need for shell access. I noticed something about bc and saw some numbers on the same line. So are you just trying to use the bc math library because php has a bc math extension.

See my other post above this one about pulling info from a text file ... I am having a hard time reading just specific parts of a text file ... anyone know how to do so ... ? I want to read what is inside a one line text file with php ( that part I can do ) but just assign one part of the line to a variable ... for example anything in the ( )

like if the text file said

hello how are you (3:45) I want to just have it open the test file and read what is inside the ( )

Then what your after is regex. Post me a few text files before insert and after insert then I shall write you the script.

all you need to do is make a .txt file that has this format

hello you are (1:45)

or and form of words but at the end have a (2:35)

or any time of sorts ... and please do write me a sample script that will capture only the numbers in the ( ) to a variable ...

Thank you so very much

Not as simple as I first thought but working on it...

Is this what your after?

<?php
$input='hello you are () ----- hello test () ';
$input2=array('(1:45)','(3:30)');
//edit above

$arr=explode('()',$input);
$result='';
for ($i=0;$i<count($arr);$i++) {
if (isset($input2[$i])) {
    $result.=$arr[$i].$input2[$i];
    } else {
    $result.=$arr[$i].'()';
    }
}
$result=substr($result,0,-2);

echo $result;
?>

What does your script do exactly ? I am curious ? my main goal is to capture the time in the ( ) and convert it to total in seconds ... so no matter what I have in the txt file it will capture the time and then convert that to seconds into a variable

example

how is today (2:35)
or
eat at home (1:25)

so what I am asking is to take say example 1 and get the 2min from the time convert that to seconds by multiplying it by 60 then add the seconds at the end of the file to get a total of 2*60+35 which would be 155 seconds ...

or in example 2 it would be 1*60+25 which would be 85 seconds ...

sorry I wasnt more clear but this needs to be read from a txt file into the variable and then computed as mentioned above

Thanks

Ow, I did the opposite and place the time into the brackets. That is even easier. The following code will do the trick.

<?php
$input='hello you are (1:45) ----- hello test (3:30) ';
//edit above

$result=array();
preg_match_all('#\(([0-9]+)\:([0-9]+)\)#',$input,$output);
for ($i=0;$i<count($output[0]);$i++) {
$result[]=($output[1][$i]*$output[2][$i]*60);
}

echo '<xmp>';
print_r($result);
echo '</xmp>';
?>

ok that is what I need but I need it to get the 2 time variables seperately as mentioned and times the first one before the : by 60 hence in your example 1*60 ( which is 60 ) and then add the second part to that at that point making it 60+45 for a total of 105 or as in your second example ... 3*60 which would be 180 and then adding the other part to that for a total of 180+30 which would be 210 ... sorry I wasnt that clear at the start ... thats what I was trying to initially do with the shell script inside the PHP ... but of you can do so all in PHP I would be most greatful ...

so what it needs to do is grab the first part of the time to one variable then * that by 60 and then grab the other side of the time and add it to the total ... obviously the : needs to be dropped as well ... please let me know ... and thank you so much for all your help sorry I wasnt clear the first time

That is only one line of code that needs altering. Surly you could alter the below line to suit your needs.

$result[]=($output[1][$i]*$output[2][$i]*60);

I took your code and corrected it to multiply the first number and then add the second and VIOLA you are the man .... now my only request is that you please tell the $input='hello you are (1:45) ----- hello test (3:30) '; variable to come from opening and reading a one line text file with the line being

whatever (2:35)

in other words opening up and reading a text file called test.txt

pulling that line and setting $input to be that line so it will work with your EXCELLENT script .... and again TY so very much

Chad

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.