Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
my string is "mom dad" (also saves the same attribute in table db).
After I query and print to the table, I want to separate a newline with a space. The output should be mom+newline+dad, but it prints "mom dad" without a new line.
Use PHP explode() function like this :
<?php
$input = "mom dad";
$inputArray = explode(" ", $input);
//now inputArray is like this ["mom", "dad", ...]
echo $inputArray[0]."<br>".$inputArray[1];
?>
Hope it helps
Thanks
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I need to use strings that contains variables that have to be interpreted after the definition of the string.
$mystring = "aaa".{$i};
...
$i=3;
echo $mystring; //Expected result: aaa3
Is it possible to load into $mystring not the value of the variable but only the name of the variable, so that its value can be loaded later?
Thanks for help.
This is a confusing question. If you want the result to be AAA3, then the code should be:
$i=3;
$com="AAA";
echo $variable = $com.$i;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have this
$words = array("Car", "Dog", "Ship");
now I want to randomly select only one word, please help!
This could work.
$words[rand(0, sizeof($words) - 1)]
You can use array_rand() function to get more than one random index.
array_rand(array, number)
<?php
$words=array("Car", "Dog", "Ship");
$random_keys=array_rand($words,3);
echo $words[$random_keys[0]]."<br>";
echo $words[$random_keys[1]]."<br>";
echo $words[$random_keys[2]];
?>
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
hi i want to create string in laravel with foreach and that string must be like this sample:
'item1,item2,item3'
Pay attention to commas and quotation marks.
anyone can help me?
you can use implode function.
Have a look at https://www.php.net/implode
It does exactly that with arrays.
example:
$string = implode(",", $array);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Using php+mysql how can i get an item from database with a criteria as shown below.
Check if string lookat(which is 'look at' without space) exist in Take an in-depth look at Wednesday's World Cup semifinal
If you have a lot of data in your table, this wouldn't be ideal. But you could do something like.
WHERE REPLACE(column, " ", "") LIKE "%lookat%"
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I would like to add + sign where ever I find space in string.
I have something like
$str = "How are you.? I'm fine."
should be
$C_str = "How+are+you.?+I'm+fine."
How I can do this in php.?
Any better idea.?
If there is just single space between chars use
$C_str = str_replace(' ','+',$str);
or if there can be more that just space like tab,etc then use this one
$C_str = preg_replace( '/\s+/','+', $str);