2017-03-23 67 views
-2
<?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}', 
     'example' => 'http://example.com/log.php?id={replace}&name={replace2}&pass={replace3}' 
    ); 

    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> 
     <option value="example">example</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> 

我想運行{replace}&name={replace2}&pass={replace3}海峽更換problemem代碼

+1

您在2016年11月發佈了幾乎相同的問題http://stackoverflow.com/q/40802230/1415724您的意思是告訴我你從那以後沒有這樣做過? –

+0

@ Fred-ii-'example'=>'http://example.com/log.php?id={replace}&name={replace2}&pass={replace3}' – awn500

+0

@ Fred-ii-很好,但我想要添加{replace2}和{replace3}謝謝 – awn500

回答

0

試試這一個,並實施適當的命名約定。

$provider = 'clody'; // replace with $_POST['D1'] 
$replacementText = 't1-text'; // replace with $_POST['T1'] 
$providers = array(
     'google_drive' => 'https://drive.google.com/file/d/{replace}/view', 
     'clody' => 'https://www.cloudy.ec/embed.php?id={replace}', 
     'example' => 'http://example.com/log.php?id={replace}&name={replace2}&pass={replace3}' 
    ); 
$url = str_replace('{replace}', $replacementText, $providers[$provider]); 
echo "Your url is " . $url;