Drama Online Drama Online - 16 days ago 6
PHP Question

Correction the code

I need your help

I have worked code display and demo, which is currently not running

I will put the code, and I hope you understand the significance of it

This code

<form method="POST" action=<?php ($_SERVER["PHP_SELF"]); ?>>
<p>chose url: <select size="1" name="D1">
<option url="https://drive.google.com/file/d/$google/view" value="google_drive">google drive</option>
<option url="https://www.cloudy.ec/embed.php?id=$cloudy" value="clody">clody</option>
</select> <input type="text" name="T1" size="40" value="insert code"> <input type="submit" value="go" name="B1"><input type="reset" value="reset" name="B2"></p>
</form>


demo

thank you all

Answer

I think you want something like this?

<?php
if(!empty($_POST['D1']) && !empty($_POST['T1'])){
    $providers = array(
        'google_drive' => 'https://drive.google.com/file/d/{replace}/view',
        'clody' => 'https://www.cloudy.ec/embed.php?id={replace}'
    );

    if(isset($providers[$_POST['D1']])){

        $url =  str_replace('{replace}', $_POST['T1'], $providers[$_POST['D1']]);
        echo "Your url is $url";
    }


}
?>

<form method="POST" action=<?php ($_SERVER["PHP_SELF"]); ?>>
    <p>chose url: 
    <select size="1" name="D1">
        <option value="google_drive">google drive</option>
        <option value="clody">clody</option>
    </select>    
    <input type="text" name="T1" size="40" value="insert code">    
    <input type="submit" value="go" name="B1"><input type="reset" value="reset" name="B2">
    </p>
</form>