Jump to content

Skip characters in a <textarea> for output


cjbeck71081

Recommended Posts

I have a form i created that takes text entered in a <textarea> and adds some tags to it like this

 

Form1.html

<form action="test.php">

<textarea>http://us10.stupid.com/Myfile.jpg</textarea>

 

What i would like to do is remove the leading 11 characters from the variable and add some tags to it so it might look like this:

 

test.php

<php

$file = $POST_['textarea'];
((((trim $file by 11 characters from the left)))))
$file1 = "<img src='http://www.";
$totalfile = "$file1'>";

echo ($totalfile);

?>

 

So that it outputs

http://www.stupid.com/Myfile.jpg

 

 

Any help is appreciated.

 

Thank You

Chris Beck

 

Link to comment
https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/
Share on other sites

Thanks guys but now to throw a wrench, (and there may not be a way of doing this) the server changes sometimes from

 

http://us10.server.com/jioasfjdasda.jpg

 

to

 

http://us2.server.com/jaksdfasa.jpg

 

but the www.server.com always works

 

so the substr works to eliminate the first 11 characters in the us10 one.  Is there any way to put a clause in that will allow for it to remove 10 characters if it a certain setup.  Possibly a "like" clause or something, i dont know.

 

Thanks for the help.

 

 

oh pishposh... lol... no need for a like statement :-) just use this :-)

 

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

$file = 'http://us10.stupid.com/Myfile.jpg';
$file = 'http://www' . get_ending($file);
echo $file;
?>

not tested... but it should work :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.