stuckwithcode
-
Posts
76 -
Joined
-
Last visited
Never
Posts posted by stuckwithcode
-
-
Where do I put this, at the top of my php page?
int mt_getrandmax ( void )
-
Hello, what is the limit of mt rand if you specify no limits,
Thanks
-
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);
-
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
-
Thanks I thought it would be simple.
-
Hello, the code below will replace the word hello with a line break.
text = text.replace(/hello/gm,"\n");
Just out of curiosity could someone please tell me how I would replace hello with the text \n not the line break.
Thanks
-
Thanks for the help.
-
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.
-
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.
-
nice clear explanation nrg_alpha, thanks
-
Thanks for the help.
-
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.
-
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?
-
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.
-
But would
$text = str_replace("\r\n", "\n", $text);
Repace \r\n and \r and \n or just \r\n
-
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?
-
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?
-
thanks for the help.
-
thanks for the help.
-
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.
-
okay, with '#[\r\n]+#', I understand now what it matches but could you explain the hash and the plus in code.
Thanks
-
Will the expression
$text = preg_replace('#[\r\n]+#', "\n", $text);
replace \r and \n and \r\n or just \r\n
-
Could someone please explain how the code below works
$text = preg_replace('#[\r\n]+#', "\n", $text);
especially the bold part.
-
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.
random number
in PHP Coding Help
Posted
So this only tells me the maximum number possible and doesn't let me set it. Also will this maximum be the same for everyone or does it change between php versions?
Thanks