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 9 years ago.
Improve this question
I have this long number 2241574459 , how can i convert this to string or readable number ?Is there any php functions ?
I know exactly how to accomplish this common task:
$variable = preg_replace(
"/\d{5,}/",
"string or readable number",
$variable
);
This will replace all 5+ digit numbers with string or readable number.
Moral of the story: Make your question clear -- how can anyone know what that integer represents? This is actually the only valid answer to it, as stupid as it is.
$text="2241574459";
$zahl=(int) $text;
Unless I misunderstand your question.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I know there are tons of questions about regex string format, but I am very new to this and I haven't been able to do it myself. How can I use regex to match a string with the following format?
xx_x_a.zip
where x is a number and a is a letter. Example:
33_2_f.zip
It must not match:
33_2_f_abc.zip
The format must always be like 2digits+_+1digit+_+1letter+.zip
Simplest way:
/^[0-9]{2}_[0-9]_[a-z]\.zip$/
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 5 years ago.
Improve this question
I need to remove this string
page=x
x being a dynamic string (should be a number but can be anything)
from another string, for example
url/?filter=value&page=2&filter2=value
but it can also be:
url/?page=2
So, these are the cases as examples
1. url/?page=2&filter=value
2. url/?page=2
3. url/?filter=value&page=2
4. url/?filter=value&page=2&filter2=value
And they should return:
1. url/?filter=value
2. url/
3. url/?filter=value
4. url/?filter=value&filter2=value
How can I do that with regex?
You've said:
[?&]page=[^&]+
works for you. This will look for an ? or & then page= and anything after it until an &. A bit longer answer though is:
echo rtrim(preg_replace('/([?&])page=[^&]*&?/', '$1', $string), '&?')
which will correctly handle the intro and ending parameter cases.
Demo: https://3v4l.org/SupbH
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have possible string combinations:
$string1 = '[variation-price] for product one.';
$string2 = 'Product two consists of [variation-parts]';
$string3 = 'Simple product';
$replace = 'Contains variations';
I need to check every string if it contains [variation- and if it does, replace the whole word (f.x. [variation-price]) with $replace.
I have tried various functions, bet the problem is that I do not know where exactly in a string variation may appear or how long it will be.
Any help or guidance is much appreciated.
Use \[variation-.*?\] regex with preg_replace():
preg_replace("/\[variation-.*?\]/", $replace, $string1)
Demo: https://ideone.com/MtNZ3L
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a set of strings that are in the format of This.is.An.Example.YYYY.More.Data.Here where YYYY is any valid year and I would like to get the string up until YYYY in the example so I would end up with a string that is This.is.an.Example.
You can do this with a simple regex, \d{4}.
$splitted = preg_split('~\d{4}~', 'This.is.An.Example.2015.More.Data');
echo $splitted[0];
Output:
This.is.An.Example.
This will split one every 4 continuous single numbers (0-9). Since you only care about what is the first instance use the 0 index.
Sample: http://sandbox.onlinephpfunctions.com/code/640224e9bda3e6cd5c3e012a1bb901dc1e6a34b4
Vague question, so I choose the simplest version ;-)
<?php
$in = 'This.is.An.Example.2015.More.Data.Here';
$out = strstr($in, '.2015', true);
echo $out;
prints This.is.An.Example
see http://docs.php.net/strstr
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a string such as this:
10,14.5,3.6,10.4,2
I'd like to round down each number so the result would be this:
10,14,3,10,2
I'm looking for the cleanest and fastest solution? My first thought was to explode them into an array and run a loop and floor each value, but that seems a little clunky to me.
I also thought that maybe using regex to just remove everything after a decimal for each value, but I don't know how to do that or if it's more efficient?
Anyone have any suggestions?
$array = explode(",",'10,14.5,3.6,10.4,2');
$string = implode(",",array_map('floor',$array));
Example