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 loaded a websites html onto a string and it has several g.load() code in the body - maybe around 10. I need this particular one which has an identifier of divId:"listing-provided-by-module".
g.load({ajaxURL:"/AjaxRender.htm?encparams=4~502222143586867513~LVuCHKHFeed3jCcefsa9MDj3xIs5wDqP7UwvtV3XDO0HnrynNRzT338AKMnzqNa4bTpgvQbff_Phk5wkav9LlWUqZfiIFKl3zXnXawc1_XDPR_9F83BlTaqhCqbfubm40s0ZciFJZV2dHzDDwlDVJJzitcXFgThESVdjnWUjJkj_MuZSVclGh7ddZ0neIHCH&rwebid=46328989&rhost=1",jsModule:"z-complaint-manager-async-block",phaseType:"scroll",divId:"listing-provided-by-module"});
What I need exactly is the ajaxURL and at the same time it checks that it is indeed with divId:"listing-provided-by-module" so it gets the correct url. Hope you can help with the regex and PHP for this. Thanks!
I've tried:
/g\.load\(\{ajaxURL:"(.*)".*divId:"listing-provided-by-module"/
But the match is too wide.
Here is the whole HTML body I want to match against: http://pastebin.com/seJd2jjc
Try this (visualized here):
'/g\.load\(\{ajaxURL:"([^"]*)",[^})]*,divId:"listing-provided-by-module"/s'
Your URL will be contained in the first capture group.
So, the PHP code would be:
<?php
$matches = [];
if (preg_match('/g\.load\(\{ajaxURL:"([^"]*)",[^})]*,divId:"listing-provided-by-module"/s', $string, $matches))
{
$url = $matches[1];
}
else
{
// No match found.
}
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 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 7 years ago.
Improve this question
Im newbie in php im learning it since some weeks ago but i didnt understand one thing.
I have a
$url = "http://example.com/";
define('LOCATION', '<?php echo $url; ?>');
but it is not working. I didnt understand why "define" term cannot read
<?php
$url = "http://example.com/";
define('LOCATION', $url);
1.You are alreay in php tag,so no need of any extra php tag.
2.And when assigning value to a variable , we never use echo in php . Its used to display value in html only.
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
}