Jump to content

Multidimensional Array Syntaxt for preg_split array using submitted textarea


Recommended Posts

I have two textarea's called textarea1 and textarea2.  What i did was use preg_split to split the textarea into seperate rows that i could use for analysis like so

$array = preg_split("/[\r\n]?[\r\n]/", $_POST['textarea2'], -1,PREG_SPLIT_NO_EMPTY);
$array2 = preg_split("/[\r\n]?[\r\n]/", $_POST['textarea1'], -1, PREG_SPLIT_NO_EMPTY);

then i used a function created for me by a nice guy on here called get_ending($filepath) which basically stripped off of each peice of text the "http://www" from every URL i put into the textareas

finishing off i wanted to create an array that would input an expression such as:

echo "<a href='$array[1]' target='_blank'><img src='$array2[1]' border='0'>";

into a text area on the next page.  ALL of this works, except that i dont know how to properly loop throught he array so it'll properly insert the text into the textarea on the next page.

For now, all it does is place the array information in the page, rather statically, i would like to run some kind of if then statement that says 

"while $array has some kind of text in it, keep running this operation of echoing the following expression adding 1 to the end of the array number"  I hope that makes sense

Any ideas?

Here is my code, so you can try it.

urltool2.html
[code]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>URL Tool</title>
</head>

<body>


<p align="center">Transform 2 URL tool </p>
<p> </p>
<form name="form1" method="post" action="wordfix2.php">

  <div align="left">
    <table width="655" border="0" align="center" cellpadding="0">
      <tr>
        <td width="325"><div align="left">
          <p align="center">Large Image URL             </p>
          <p>
            <textarea name="textarea2" cols="50" rows="50" wrap="off" id="textarea2"></textarea>
            </p>
        </div></td>
        <td width="324"><div align="right">
          <p align="center">Thumbnail URL </p>
          <p>
            <textarea name="textarea1" cols="50" rows="50" wrap="off" id="textarea1"></textarea>
            </p>
        </div></td>
      </tr>
          </table>
  </div>
  <div align="center"></div><p align="center"> </p>
  <p align="center">
    <input type="submit" name="Submit" value="Submit" />
    </p>
</form>
<p align="center"> </p>
</body>
</html>

 

wordfix2.php

[code
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Adjusted URLS</title>
<?php

function get_ending($filepath){
return substr($filepath, strpos($filepath, strchr($filepath, ".")));
}

$array = preg_split("/[\r\n]?[\r\n]/", $_POST['textarea2'], -1, PREG_SPLIT_NO_EMPTY);
$array2 = preg_split("/[\r\n]?[\r\n]/", $_POST['textarea1'], -1, PREG_SPLIT_NO_EMPTY);


?>

</head>

<body>
<div align="center">
  <p>Adjusted URLS </p>
  <p>   </p>
  <p>
    <textarea wrap="off" cols="100" rows="50"><?php

echo "<a href='$array[0]' target='_blank'><img src='$array2[0]' border='0'>
";
echo "<a href='$array[1]' target='_blank'><img src='$array2[1]' border='0'>";
?>
    </textarea>
  </p>
</div>
</body>
</html>
[/code]

 

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.