lundi 30 mars 2015

Echoing part of a PHP string back within conditional value of HTML form field

I am building an HTML form - a simplified, two field version of which is below. The user is meant to enter something like the below string into the first field of the form:



http://ift.tt/1GBKO24
%2Fbit.ly%2F12345&picture=http://ift.tt/19bUfYK;
description=Description&redirect_uri=http%3A%2F%2Fwww.facebook.com%2F&
caption=Something


I am trying to split this string so that only the following part of the string is echoed into the second field of the form:



horse-picture.jpg


If the first field is empty, the second field is echoing back its own value. I've marked where the trouble is below. I've seen several threads on using explode, but the part of the string I'm looking to echo back isn't flanked with the same consistent characters, and the length of this string will vary, so preg_match also seems to be not a good option. Having this nested within a conditional is also throwing me off. Would very much appreciate help. Thanks!



<h2>THIS IS AN HTML FORM</h2>
<form action="sharefile.php" method="post">

<label for="decode">FB decode:<br /></label>
<input type="text" id="decoder" name="decoder" size="70" value="" /><br /><br />

<label for="img">Image (e.g. horse-picture.jpg):<br /></label>
<input type="text" id="img" name="img" size="70" value="

<?php if (strlen($_POST['decoder']) > 0)

//THIS IS WHERE THE TROUBLE STARTS
{SOMETHING GOES HERE}
//THIS IS WHERE THE TROUBLE ENDS

else {echo $_POST['img'];}
?>"


<input type="submit" value="Submit!" name="submit" />

</form>

Aucun commentaire:

Enregistrer un commentaire