Search code examples
phpbashnginxhttp-live-streaming

Php and bash together to generate keys


I have this bash file which generates key and expire time :

#!/bin/bash
get_customer_url() {
  local IP=${1:-127.0.0.1}
  local SECRET=${2:-VERY_COOL_SECRET}
  local EXPIRES="$(date -d "today + 30 minutes" +%s)";
  local token="$(echo -n "${EXPIRES} VERY_COOL_SECRET" | openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d =)"
  echo "/${token}/${EXPIRES}/"
}
get_customer_url

and i call it via php like this

<?php $output = shell_exec('sh generate-keys-hls.sh'); echo "$output";?>

it works fine , it generates something like this

/G8INKLc3VfDMYtQT2NTU-w/1530222035/ 

my problem is i want to put another php result in the some line like this

<?php $output = shell_exec('sh generate-keys-hls.sh'); echo "$output";?><?php echo get_post_meta($post->ID, 'file', true)?>

currently its printing the result in two lines i need it to be one just one line instead of this

/G8INKLc3VfDMYtQT2NTU-w/1530222035/ 
file.mp4.m3u8

i want it to be like this

/G8INKLc3VfDMYtQT2NTU-w/1530222035/file.mp4.m3u8

without white spaces or multiple lines !


Solution

  • Remove the whitespace around the result of shell_exec().

    echo trim($output);