Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
$data[10] = "12.21661,13.00128";
$loc = explode(",",$data[10]);
$lat = $loc[0];
$long = $loc[1]; **// Undefined offset:1**
When i run above code I got error on $long = $loc[1]; line (Undefined offset:1).
How can I resolve this??
The data in string is 2 digits and 5 decimals. if the number have fixed limits then there is function in PHP : str_split()
Here's documentation , Look at an example , it will be much clear.
it will split in exact length like
Check example : Example #1 Example uses of str_split() in documentation
http://php.net/manual/en/function.str-split.php
or
there is explode() function
http://php.net/manual/en/function.explode.php
does exactly what you want , I guess.
check out , examples are quite simple.
Any query comment back.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I've made progress here , updating this support request .. i cannot add code to this it won't save - this is very difficult , spent 5 minutes sending this simple message.
ltrim removes prefix "/" AND ..
preg-replace remove suffix "?page=*"
so that :
URL = /city = city
URL = /city?page=* = city
You can't use <?=...?> inside a string, that can only be used when you want to print something from a context that's printing literal text.
Either use variable interpolation in a double-quoted string:
if($host == "https://www.purelocal.com.au/{$profession[filename]}")
or concatenation:
if($host == 'https://www.purelocal.com.au/' . $profession[filename])
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I can't seem to get this correct.
I have this PHP command that I need to do the same thing in Python:
preg_match("/^(collabedge-|cb|ss)([0-9]+).dc-([0-9]+).com$/", $domain, $matches);
I have three possible string formats:
domain = collabedge-123.dc-01.com
domain = cb123.dc-01.com
domain = ss123.dc-01.com
I need to pull out the 123 and 01 from the string no matter what the format of the string and assign to variables.
You can use this code:
import re
domain = "collabedge-123.dc-01.com"
# preg_match("/^(collabedge-|cb|ss)([0-9]+).dc-([0-9]+).com$/", $domain, $matches);
regex = r"^(collabedge-|cb|ss)([0-9]+).dc-([0-9]+).com$"
res = re.match(regex,domain)
print(res.group(0))
print(res.group(1))
print(res.group(2))
print(res.group(3))
Output:
collabedge-123.dc-01.com
collabedge-
123
01
As sure as I posted the question I kept trying and figured it out. For those that want to know the answer.
d = re.match(r"(collabedge-|cb|ss)([0-9]+)\.dc-([0-9]+)\.com", domain)
firstnum = d.group(2)
secnum = d.group(3)
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
My value is coming like this with two enters. please see below :
125
124
132
I am getting this value by php variable and want to get values with commas in new php variable.
i want like this 125,124,132
anyone have an idea for that please?
$str = "125
124
132";
$str = str_replace("\r\n\r\n", ",", $str);
echo $str;
Try the above code. Please let know if this worked.
You can directly add commas between numbers using
number_format() function of PHP
<?php
echo number_format("125124132")."<br>";
?>
Answer:- 125,124,132
Try the above given code and let me know if this worked.....
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I need to get a substring (see examples, bold part) from the string. All strings begin with "input" followed by 2 underscores with some (1 to 7) random chars between. Thank you!
Examples:
input_7ax8_SOME_INFO
input_3f0max2_SOME_OTHER_INFO
input_k_ANOTHERINFO-any-chars-possible:0123456789
Using the detection of "non underscore" + "underscore" times 2 and fetching everything that comes after that you can get the result you ask.
The ?: is meant for not returning the result of the parts with underscores because the () are needed to combine it together.
$input = 'input_k_ANOTHERINFO-any-chars-possible:0123456789';
preg_match( '~^(?:[^_]+_){2}(.*)$~', $input, $match );
var_export($match);
You just need explode and its third param :
<?php
$input = 'input_7ax8_SOME_INFO';
$input = explode("_",$input,2); // Split 2 times
$input[2] = '<b>'.$input[2].'</b>'; // Make the rest of the string bold
$input = implode("_",$input); // re joining
echo $input;
?>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a simple php program which is getting the data from the url, but I want to check whether it contains a alphabet or not.
The data which I get from the url is as follows ?query=seller,12. I used ctype_alpha() for this, but I am getting no result for this. I have a rough idea that it can be done by preg_match() but I don't how to do it.
Please help me as I am beginner to php.
Thanks in advance
Here you go,
<?php
$subject = "?query=seller,12";
if(preg_match('/[a-zA-Z]/', $subject)){
echo "It has a alphabet";
}
?>
if you want to print all the characters from that string, you can use like this
preg_match_all('/[a-zA-Z]/', $subject,$matches);
print_r($matches);
$matches is an array of all available matches of the specified pattern
Try this dude.
if (!preg_match('/[^A-Za-z]/', $string)) // '/[^a-z\d]/i' should also work.
{
// string contains only english letters
}