PHP for : IF URL = string else [closed] - php

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])

Related

Php string concatenating variables with forward slash [closed]

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 am trying to create a unique id by concatenating 3 variables using forward slashes(/). my code is like so
$year . "/" . $acronym . "/" . $num;
I am expecting an output of
"18/MC/1"
but the output I get is
"18\/MC\/1"
What am I doing wrong. I have already tried using stripslashes() but it doesn't do anything to the output.
You could use join function
<?php
// ...
join([$year, $acronym, $num], '/');
For more info, see: Join function documentation
I found what was wrong,
The code below outputs the correct format 18/MC/1
return response()->json([$id]);
while my previous code was
return response()->json($id);
which gave me an output of
`"18/MC/1"
There is function in php to remove backward slash from string use following function.
echo stripslashes(string);
output: 18/MC/1

Disable errors when getting postal code using ipapi.co [closed]

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 6 years ago.
Improve this question
I'm retrieving the postal code by using -
<?php $pstcde = file_get_contents('https://ipapi.co/'.$_SERVER['REMOTE_ADDR'] . '/postal/'); ?>
It works great but if the postal code is not found, it says, "None". I can't find a way to disable the message.
You can empty the variable if the respond is None. With a simple check.
<?php
$pstcde = file_get_contents('https://ipapi.co/'.$_SERVER['REMOTE_ADDR'] . '/postal/');
if($pstcde === "None")
$pstcde = ""; //Empty string. Or you can use unset($pstcde); if you want to unset the variable.
?>

In PHP, echo a div with the id of a variable [closed]

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 6 years ago.
Improve this question
i want to echo a div in PHP, and set the ID equal to the value of $divName, but i cannot get it to work
Here is my code:
$divName = "divText"
echo '<div id=$divName></div>'
Just do it like this:
$divName = "divText";
echo '<div id="'.$divName.'"></div>';
You should read the PHP Documentation. This is really basic stuff.
http://php.net/docs.php
Why you don't add semicolons (;) at the end of each command line?
Change single quotes (') to double quotes (") and that it:
$divName = "divText";
echo "<div id=$divName></div>";

PHP Regex: extracting dynamic url from page body html [closed]

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.
}

How can i write " in php [closed]

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
function wrap($str) {
$str="[#id=\"".$str."\"]";
return($str);
}
$str="Hi";
$str=wrap($str);
I would have $str like [#id="Hi"], but i have $str like [#id=\"Hi\"]
How could i do that?
$str='[#id="'.$str.'"]';
replace " with '
The code works as expected, no need to change quotes to single ticks or remove the second pair of double quotes.
Probably the backslashes are added later. If you just echo $str; after your snippet it shows this in a browser
[#id="Hi"]

Categories