Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have some problem.
I have some data from my post on date range picker
there are
"10/04/2013 - 10/26/2013"
I want to get
date1 = "10/04/2013"
and
date2 = "10/26/2013"
for my between date query..
please help me
Thank you for your attention
You need to use explode()
$string="10/04/2013 - 10/26/2013"; //Your string
$exploded = explode('-', $string); //Explode using -
echo $exploded[0]; //echo string 1
echo $exploded[1]; //echo string 2
Note: You will have to use trim() if you want to get rid of the white space, else in the explode() first parameter, use the spaces before and after the - like explode(' - ', $string)
For mysql query the date format should be as "YYYY-mm-dd"
Your input comes as MM/dd/YYYY
You may need to convert that to mysql format before firing the query
In that case you can use strtotime()
date("Y-m-d",strtotime("10/04/2013"));
will give you 2013-10-04
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have my string which may vary in lenght
$k= "2013-01-0112:00:002013-01-0212:00:002013-01-0312:00:00";
I'm looking for substr(), str_replace() or any other function my return me this
$newstring= ('2013-01-01 12:00:00'), ('2013-01-02 12:00:00'), ('2013-01-02 12:00:00')
I should use a kind of for each 18 charcters as the dates of the original string may vary.
My intent is to build then a "INSERT INTO" MYSQL query with all the generated dates in the column "date".
id date
null 2013-01-01 12:00:00
null 2013-01-02 12:00:00
null 2013-01-03 12:00:00
Split string on every 18th position. Then add space on every value of the array on 10th position.
$k = "2013-01-0112:00:002013-01-0212:00:002013-01-0312:00:00";
$a = str_split($k, 18);
$a = array_map(function($dt) {
return implode(' ', str_split($dt, 10));
}, $a);
print_r($a);
Demo.
If you wish to add character to N-th position:
$k = "2013-01-0112:00:002013-01-0212:00:002013-01-0312:00:00";
echo implode(',', str_split($k, 18));
// ^ ^
// character N-th position
Demo.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to remove a particular match of characters from a string.
For example i have strings;
topics-p10-new-model-cars
topics-p20-new-model-cars
topics-p30-new-model-cars
topics-p40-new-model-cars
Then i need the results as,
topics-new-model-cars
topics-new-model-cars
topics-new-model-cars
topics-new-model-cars
That means i want to remove p10-,p20-,etc..
.Those are the page numbers. It may be any number..
How can i do this..? Thanks in advance
Try this:
$result = preg_replace('/\-p\d+/', '', $string);
Note: I'm assuming that the string format does not change (I mean this [topics-p10-new-model-cars]). If my assumption is right.
Then you can do this
if (textBox1.Text.Contains("-p10-"))
{
//topics-p10-new-model-cars
String[] splited = textBox1.Text.Split(new char[] {'-'});
String rString = String.Format("{0}-{1}-{2}-{3}",
splited[0],splited[2],splited[3],splited[4]);
MessageBox.Show(rString);
}
//OR This method
if (textBox1.Text.Contains("-p10-"))
{
String result = textBox1.Text.Replace("p10-", "");
MessageBox.Show(result);
}
With 'preg-replace'::
For, example:
<?
echo preg_replace('/p[0-9]+\-/', '', 'topics-p10-new-model-cars');
?>
Follow this link:
http://www.php.net/manual/en/function.preg-replace.php
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
When I type:
<?php
$temp="1234";
echo "<script type='text/javascript'>document.write({$temp});</script>";
?>
I get 1234 on the screen.
But when I replace $temp="1234" with $temp="alfa" I get nothing on the screen.
What's the problem ? Where am I wrong ? "1234" and "alfa" are both strings
alert(1234) is valid javascript, and will simply pop up the integer 1234 on your screen.
alert(alfa) is attempting to pop up the contents of a variable named alfa on your screen, which doesn't exist.
If you're insert data from PHP into a Javascript context, you MUST use json_encode() to ensure that you're producing VALID javascript. e.g.
$temp = 'alfa';
$json= json_encode($temp);
echo '<script>.... {$json}...</script>';
that will produce alert('alfa') and work as expected.
You aren't enclosing the text in the double-quote character '"' which denotes a string.
document.write(1234) works because 1234 is a valid value in JavaScript (an integer), whereas alfa is a symbol name, it should be "alfa".
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Hi i have an dynamic string like this 5,6,7,8,11,25 in my database. I want to count how much numbers are in the string. In my example there are 6. But I don't find a solution. Please help me.
MySQL lacks an explode function so you have to query the data and do the count in php using explode() and count().
count(explode(",", $string));
The explode() function breaks the string into an array element for each string separated by a comma, and then the count() function returns the number of elements in that array.
$numbers = explode(',', '5,6,7,8,11,25');
echo count($numbers);
try something like
your string
$str = '5,6,7,8,11,25';
then use explode to convert the string into an array
$str_array = explode(',', $str);
and to get the number of elements of the array
$size = count($str_array);
To count the numbers you will have to use something like:
count(array_filter(explode(',', $string), "is_numeric"))
But be careful, every string value that looks numeric will be counted.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have some SQL fields which I need to show as the heading of the table in PHP
Following are some of my fields names and I want to show them as Following strings
market_name =>Market Name
company_name => Company Name
company_address => Company Address
operating_hours => Operating hours
Is there any String Formatting option in there ?
You can combine ucwords() and str_replace() to produce the required result:
Code:
$strings = array('market_name', 'company_name', 'company_address', 'operating_hours');
foreach($strings as $string){
$string = ucwords(str_replace('_', ' ', $string));
echo $string."<br>";
}
Output:
Market Name
Company Name
Company Address
Operating Hours
Documentation: ucwords(), str_replace()
Hope this helps!
This should do the trick:
$string = "market_name";
//replace the underscore with whitespace
$step1 = str_replace("_", " ", $string);
//capitalize the words
$step2 = ucwords($step1);
//this will give you
Market Name