php - How to cut string between two | symbols?

263

FirstString | 2ndString | 3rdString

$1stString = substr($WholeString, 0, strpos($WholeString, '|'));

Now I want to get the 2nd and 3rd string as well, but don't know how.

Thanks.

196

Answer

Solution:

You can use explode:

$str = "FirstString | 2ndString | 3rdString";

$results = explode('|', $str);

print_r($results);

People are also looking for solutions to the problem: PHP convert ' to html code

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.