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 Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/ 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 ?> Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/#findComment-259081 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() Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/#findComment-259085 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! Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/#findComment-259086 Share on other sites More sharing options...
taith Posted May 22, 2007 Share Posted May 22, 2007 aww poor fearpig... *pats on the back* Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/#findComment-259091 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. Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/#findComment-259112 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? Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/#findComment-259114 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 Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/#findComment-259117 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 Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/#findComment-259131 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... Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/#findComment-259135 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; ?> Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/#findComment-259145 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 Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/#findComment-259149 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 Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/#findComment-259178 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 ;-) Link to comment https://forums.phpfreaks.com/topic/52504-skip-characters-in-a-for-output/#findComment-259190 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.