cjbeck71081 Posted May 22, 2007 Share Posted May 22, 2007 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted May 22, 2007 Share Posted May 22, 2007 <?php $file = 'http://us10.stupid.com/Myfile.jpg'; $file = 'http://www' . substr($file, 11); echo $file; //--> http://www.stupid.com/Myfile.jpg ?> Quote Link to comment Share on other sites More sharing options...
Fearpig Posted May 22, 2007 Share Posted May 22, 2007 A quick look round and I'm sure you can use: explode() - http://uk3.php.net/manual/en/function.explode.php or preg_split() or split() Quote Link to comment Share on other sites More sharing options...
Fearpig Posted May 22, 2007 Share Posted May 22, 2007 ...and Barand not only types quicker but comes up with a much better way of doing it! Quote Link to comment Share on other sites More sharing options...
taith Posted May 22, 2007 Share Posted May 22, 2007 aww poor fearpig... *pats on the back* Quote Link to comment Share on other sites More sharing options...
cjbeck71081 Posted May 22, 2007 Author Share Posted May 22, 2007 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. Quote Link to comment Share on other sites More sharing options...
cjbeck71081 Posted May 22, 2007 Author Share Posted May 22, 2007 Perhaps the pregsplit would work in this case if you put in a removal clause of "http://" and "us10" and "us2" and any other servers they commonly use. Any Ideas? Quote Link to comment Share on other sites More sharing options...
taith Posted May 22, 2007 Share Posted May 22, 2007 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 Quote Link to comment Share on other sites More sharing options...
cjbeck71081 Posted May 22, 2007 Author Share Posted May 22, 2007 get_ending is not a function of PHP Quote Link to comment Share on other sites More sharing options...
taith Posted May 22, 2007 Share Posted May 22, 2007 it is after i made it... not a default one, but you can make your own... Quote Link to comment Share on other sites More sharing options...
chigley Posted May 22, 2007 Share Posted May 22, 2007 This is how I'd do it: <?php $file = "http://us10.stupid.com/Myfile.jpg"; $bits = explode(".", $file); $file = "http://www." . $bits[1] . "." . $bits[2] . "." . $bits[3]; echo $file; ?> Quote Link to comment Share on other sites More sharing options...
taith Posted May 22, 2007 Share Posted May 22, 2007 ya... mine grabs everything after the first . as in... http://www.google.ca --> google.ca and https://wwwl.google.com --> google.com Quote Link to comment Share on other sites More sharing options...
cjbeck71081 Posted May 22, 2007 Author Share Posted May 22, 2007 Worked Great man, thanks alot. As soon as i think i know alot about this language, u guys kick my a$$ Thanks Chris Quote Link to comment Share on other sites More sharing options...
taith Posted May 22, 2007 Share Posted May 22, 2007 lol... no prob... functions make the world go round ;-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.