email - Find the count of occurrences of a substring within a string in php

86

I have a string say

$result = \nHey there!Listen\n\n===\n\nLife is one\n\n===\n\nBut cs is 1.6ok\n\n===\n\nI hope you got what i wanna say\n\nSpeech finished\n\n===\n

Now I want to

  1. Find the no of occurences of\n in the above string. I have used the below function but it outputs nothing :

    substr_count($result,"\n");
    
  2. I want to email$result as the Email-body , but\n characters are appearining as it is. Anyway out there, that I can get rid of these\n characters and they are actually replaced by a new line in email subject ?

245

Answer

Solution:

$result = str_replace("\n", chr(13), $result );

I replaced all the \n characters by chr(13) that is interpreted as enter .

So it worked out for me :)

People are also looking for solutions to the problem: PHP and MYSQL sessions

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.