943,169 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 44
  • PHP RSS
Sep 3rd, 2010
0

Need help to search string beginning for http://

Expand Post »
Hello everyone! First of all thanks to all who helped in the past on my c++ problems, but now I need help with some php. I'm trying to search the beginning of a string for the http:// string but am having trouble with it. I can find the string inside the string but can't find it at the beginning of the string. In my attached code I wrapped a strpos() function inside of a substr() function and am trying to search the start of the string and stop the search after the http:// characters. I've tried changing the number of characters from 0 to 1 and 7 to 6 because strings start at 0 I suppose? Also, what about using JavaScript to check instead? although I'd rather use php. Any help would be greatly appreciated. Thank you!
PHP Syntax (Toggle Plain Text)
  1. $start = 0;
  2. $end = 6;
  3. $string = "http://";
  4. if (substr(strpos($url, '$string'), '$start', '$end') === false ) {
  5.  
  6. die("Link must begin with http://");
  7. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
c++learner is offline Offline
27 posts
since Jul 2010
Sep 3rd, 2010
0

Update

By the way, just thought that I would tell you that I'm not getting any syntax errors with this code, it's just not working.
Click to Expand / Collapse  Quote originally posted by c++learner ...
Hello everyone! First of all thanks to all who helped in the past on my c++ problems, but now I need help with some php. I'm trying to search the beginning of a string for the http:// string but am having trouble with it. I can find the string inside the string but can't find it at the beginning of the string. In my attached code I wrapped a strpos() function inside of a substr() function and am trying to search the start of the string and stop the search after the http:// characters. I've tried changing the number of characters from 0 to 1 and 7 to 6 because strings start at 0 I suppose? Also, what about using JavaScript to check instead? although I'd rather use php. Any help would be greatly appreciated. Thank you!
PHP Syntax (Toggle Plain Text)
  1. $start = 0;
  2. $end = 6;
  3. $string = "http://";
  4. if (substr(strpos($url, '$string'), '$start', '$end') === false ) {
  5.  
  6. die("Link must begin with http://");
  7. }
Reputation Points: 10
Solved Threads: 0
Light Poster
c++learner is offline Offline
27 posts
since Jul 2010
Sep 3rd, 2010
0

Stepping out

One more thing, I have to stop for now and won't be on until late tonight, so I'll check back then.
Thank you for your help.
Click to Expand / Collapse  Quote originally posted by c++learner ...
Hello everyone! First of all thanks to all who helped in the past on my c++ problems, but now I need help with some php. I'm trying to search the beginning of a string for the http:// string but am having trouble with it. I can find the string inside the string but can't find it at the beginning of the string. In my attached code I wrapped a strpos() function inside of a substr() function and am trying to search the start of the string and stop the search after the http:// characters. I've tried changing the number of characters from 0 to 1 and 7 to 6 because strings start at 0 I suppose? Also, what about using JavaScript to check instead? although I'd rather use php. Any help would be greatly appreciated. Thank you!
PHP Syntax (Toggle Plain Text)
  1. $start = 0;
  2. $end = 6;
  3. $string = "http://";
  4. if (substr(strpos($url, '$string'), '$start', '$end') === false ) {
  5.  
  6. die("Link must begin with http://");
  7. }
Reputation Points: 10
Solved Threads: 0
Light Poster
c++learner is offline Offline
27 posts
since Jul 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how to show the current date and time in my database tables
Next Thread in PHP Forum Timeline: encryption help at login





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC