Jump to content

Recommended Posts

$string = substr($text, 0, 5);

if ($string == "start") {echo "contains the start string!"}

else {echo "doesnt contain the start string!"}

 

I think this is what you want, btw, change 5 to the number of strings of the start word, like "start" has 5 characters.

Ted

Link to comment
https://forums.phpfreaks.com/topic/36941-solved-if-begins-with/#findComment-176261
Share on other sites

Well, strpos() "Returns the numeric position of the first occurrence of needle in the haystack string" (from the manual). It returns FALSE if it wasn't found, and that's why you need to use the === operator (because 0==FALSE is true, and 0===FALSE is false).

 

Orio.

Link to comment
https://forums.phpfreaks.com/topic/36941-solved-if-begins-with/#findComment-176266
Share on other sites

Can you just confirm where the field would go in there, and where the text i am looking for would go in there? is it;

 

$string - where it gets the field

 

$start - the text i want to search for in the field

 

And what does the '=== 0' do?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/36941-solved-if-begins-with/#findComment-176269
Share on other sites

1 last question, how would i be able to say if it starts with this or this?

 

What i have so far is:

<?php
if(strpos($qry[link], "http://") === 0)
echo "Starts!";
else
echo "Doesn't!";
?>

 

But if i try putting the or operator (||) after it always says 'doesnt'.

 

Thanks :)

Link to comment
https://forums.phpfreaks.com/topic/36941-solved-if-begins-with/#findComment-176278
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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