| |

VerySource

 Forgot password?
 Register
Search
View: 942|Reply: 5

May I ask a function

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-16 12:40:01
| Show all posts |Read mode
I am a novice in PHP. I can determine whether a variable $ a contains the character of $ b in another variable. What method can I use to achieve it, thank you
Reply

Use magic Report

0

Threads

12

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-21 10:45:01
| Show all posts
strpos

<? php
$ mystring = 'abc';
$ findme = 'a';
$ pos = strpos ($ mystring, $ findme);

// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($ pos === false) {
    echo "The string '$ findme' was not found in the string '$ mystring'";
} else {
    echo "The string '$ findme' was found in the string '$ mystring'";
    echo "and exists at position $ pos";
}

// We can search for the character, ignoring anything before the offset
$ newstring = 'abcdef abcdef';
$ pos = strpos ($ newstring, 'a', 1); // $ pos = 7, not 0
?>
Reply

Use magic Report

0

Threads

12

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-1-21 12:00:01
| Show all posts
strpos ($ b, $ a);
// Returns the position of a in b, or returns FLASE if not
Reply

Use magic Report

0

Threads

17

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-1-21 23:36:01
| Show all posts
Someone has asked the same question before. The solution is to specify a flag variable in the previous function.jinjialinsaid the program, yes, you can use it after you understand the meaning inside
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Canada

Post time: 2020-1-23 11:18:01
| Show all posts
The landlord asked if it contains the character of $ b in another variable,
strpos is the entire string
Reply

Use magic Report

0

Threads

27

Posts

18.00

Credits

Newbie

Rank: 1

Credits
18.00

 China

Post time: 2020-1-28 09:18:01
| Show all posts
strpos
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list