Jump to content

stuckwithcode

Members
  • Posts

    76
  • Joined

  • Last visited

    Never

Posts posted by stuckwithcode

  1. How can i put

    name = array[1];

     

    where name is an array of names, i cant seem to get this to work, can you help?

     

    var text    = "hello peter, you are awesome.";

    var name    = "peter";

    var replace  = "mark";

     

    var regex    = new RegExp(name, "g");

    text = text.replace(regex, replace);

  2. Hello, with the code below how could I amend it to replace a variable for a variable

     

    text = text.replace(/peter/gm,"mark");

     

    eg

     

    var name = "peter";

    var repname = "mark"

     

    How do i put variables in the code instead of strings

     

     

  3. Hello,

     

    The code below alows me to replace the sequence ", , " with just one ", "      (comma then a space)

     

    text = text.replace(/[,]\s[,]\s/gm,", ");

     

    How can I amend the code so that however many I have in a row eg . ", , , , , " or ", , , " all get changed to one ", "

     

    Thanks.

     

  4. Hello, I understand how wordwrap works in php and have used it well before.  However when I used wordwrap on a variable that is going to be emailed it puts the line breaks in well before it should.  The code is below.

     

    $name = thisisaname

    $email = thisisanemail

     

    $text = "Account name:"."  ".$name."      "."Account email:"."  ".$email."\r"."\r";

     

    $text = wordwrap($text,90,"\r");

     

    If i change word wrap to 50 it wraps it after the word Account? any help.

     

  5. Thats exactly what I wanted.  Can you please tell me how "#[\r\n]{1,2}#" achieves what I wanted, what does the 1 and 2 do.

     

    Will this code work for multiple lines in a row or is there a limit.

    Thanks.

  6. but what if there are two line breaks as below:

     

    $text = "this is just \r test \r\n\r\n text inside \n of text \n\r more text";

     

    the echo should be:

     

    this is just

    test

     

    text inside

    of text

    more text

     

    but instead it is:

     

    this is just

    test

    text inside

    of text

    more text

     

    How can I keep the multiple line breaks?

  7. If i take the text

     

    a

    b

     

    and put it into the function the one line break get doubled.

     

    e.g  a\r\nb goes to a\r\n\r\nb what am I doing wrong.  I just want to convert all types of line breaks to \r\n and keep the number of line breaks.

  8. Hello I have this code below that converts all types of line breaks to \r\n.

     

    $text = preg_replace('#[\r\n]+#', "\n", $text);

     

    But if there are 5 line breaks it groups them to 1.  I want to keep the number of line breaks the same, just make them all the same format.    If I remove the + it seems to double the actual number of line breaks.  Can anyone help?

  9. Hello I have this code below that converts all types of line breaks to \r\n.

     

    $text = preg_replace('#[\r\n]+#', "\n", $text);

     

    But if there are 5 line breaks it groups them to 1.  I want to keep the number of line breaks the same, just make them all the same format.    If I remove the + it seems to double the actual number of line breaks.  Can anyone help?

  10. So I could use the code below instead of $text = preg_replace('#[\r\n]+#', "\n", $text);

     

    $text = preg_replace('/[\r\n]+/', "\n", $text);

     

    and the + means it looks for more than one occurrence of:

     

    \r

    \n

    \r\n

    \n\r

     

    Or does the + means it will look for the different combinatons which you said were

     

    \r

    \n

    \r\n

    \n\r

     

    Sorry if question sounds stupid.

  11. oni-kun Thanks for the reply but I didn't quite understand your explanation of how I got

     

    a\r\r\n\r\nb\r\r\n\r\nc

     

    and could someone explain how

     

    $text = preg_replace('#[\r\n]+#', "\r\n", $text);

     

    works.

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