Strip from 15th character to the end

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Strip from 15th character to the end

Post by flying_circus »

Dear god, this is just painful to watch!

Code: Select all

$end = substr($url, 14);
azylka
Forum Commoner
Posts: 40
Joined: Sat Dec 06, 2008 9:11 pm

Re: Strip from 15th character to the end

Post by azylka »

$end = substr('$url', 0, 16); is what I really want. I want to dispose of all of the characters after the first 15 characters. How do I use this snippet with a variable?

I'm glad someone is helping me. (Cough cough)

Cheers,
Alex
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Strip from 15th character to the end

Post by flying_circus »

Remove the quotes encapsulating your variable

Code: Select all

$end = substr($url, 0, 16);
azylka
Forum Commoner
Posts: 40
Joined: Sat Dec 06, 2008 9:11 pm

Re: Strip from 15th character to the end

Post by azylka »

flying_circus wrote:Remove the quotes encapsulating your variable

Code: Select all

$end = substr($url, 0, 16);
Thanks. I'm glad someone around here is nice. I've already got it, but it's the thought that counts!

Cheers,
Alex
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: Strip from 15th character to the end

Post by prometheuzz »

azylka wrote:
flying_circus wrote:Remove the quotes encapsulating your variable

Code: Select all

$end = substr($url, 0, 16);
Thanks. I'm glad someone around here is nice. I've already got it, but it's the thought that counts!

Cheers,
Alex
By saying that the people [other than me] who didn't just post a spoon-feed answer are not nice is a rather ungrateful thing to say, IMO.
I highly recommend reconsidering a career-change if you must rely on this kind of "help".
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Strip from 15th character to the end

Post by Christopher »

azylka wrote:Thanks. I'm glad someone around here is nice. I've already got it, but it's the thought that counts!
I don't think they were "nice." I think they simply could not stand it anymore and were merciful.

I want be clear with you that PHP is a ridiculously interactive language. You type in echo substr($mystring, 0, 5);, hit refresh, and it shows you what it did. You type in echo substr($mystring, 0, 15); and it shows you that. Same with echo substr('$mystring', 0, 15);.

I noticed from what you posted that your method of attempting to solve the problem was flawed. You did substr("$url", -15); first and then changed two things for substr('$url', 0, 15);. How would you know if the quotes or the start/length was the problem? You need to check the manual, start with functioning code, and make one change at a time as you learn how something works.

PHP has a great online manual with many, many examples. And to be honest, if you can't figure out substr() on your own, then you probably can't figure out anything in PHP. You can get lots of free help here, but you have to show people that you don't just want them to do your work for you. Remember, it is free help.
(#10850)
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: Strip from 15th character to the end

Post by JAB Creations »

I didn't know this would blow up in to a two page thread. No harm was intended.

My point was pretty simple...there are examples on the page arborint linked to. If you don't know how something works read the documentation and change things on your own in a test file. I've done that sort of thing countless times versus getting my post count up to 12,000 on here.

Copy and paste, save, load the page...not what you want? Change a number...try positive, negative, etc...and repeat until you learn the pattern.

Learning to learn is a fundamental part of programming. I've done it, made more then my fair share of mistakes, though I finally caught on, at least for the most part.

But ultimately there is one last point: we'll help each other try to figure things out but no one is going to just simply and blindly give out answers. If you need this by a certain time then you're the one getting paid to know something in which case you should be more then aware that you should learn it or find a different job. It's a bit of tough love but that's how the world works.

If you're going to learn this stuff I recommend you spend two minutes learning how to explode stuff, it's fun, it's dead simple, and there are examples that work right off the documentation that you can change and experiment very easily with. Everyone here will agree that php.net is simply the model for a programing documentation website. Ask more questions like what built in function would others suggest, why isn't it doing this or that with different letter casing, or how you would approach a more complex issue where you might combine various functions. Make your test.php file, copy/paste, save, load it in a browser, and then tweak and repeat. This stuff is much simpler if you make a real effort. :wink:
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Strip from 15th character to the end

Post by flying_circus »

arborint wrote:I don't think they were "nice." I think they simply could not stand it anymore and were merciful.
:mrgreen:


I do agree that having to wait almost 17 hours to find a solution to a problem, such as the one presented, is WAY too long.

Within that time frame, I would speculate that it would be more efficient to read the manual, search google, or go to your local book store and purchase a book on getting started with PHP. But why would one invest their own time in solving a problem when you have an active community if people willing to offer up their services for free? :banghead:

I probably would have skipped clean over this thread had is not been for the amount of replies and the severity of the hazing.
Post Reply