How to deal with 'µg' in PHP? - php

So I am having problems with the symbol µg in PHP. The symbol is inside an array of data but I can't seem to match it with the following:
if($value == 'µg') {
echo 'blah';
}
Does anyone happen to have a work around for this? I'm assuming PHP saves it as a different type then what I am comparing it to because it never echo's the 'blah' above. I have searched around for a while now and cannot find anything to help me. Thanks!

Okay so even with the help of some people I haven't found the answer.
The best I came up with that actually works is:
substr('µg', 1,7) == 'micro;g'
That's the only way I found out how to parse the data. If you put the & in front of the micro; you get the µ. A dirty fix but if anyone has a way around please let me know. Thanks!

Related

PHP Array in Google Maps

I'm pulling google map data into a php array from MySQL. I have used this code as a base:
https://github.com/rajkavinchetty/Google-Maps-API-with-PHP-MySQL/blob/master/index.php
It almost works perfectly. The lat/long data is pulled from the array and sets-up the markers.
...
$locations[]=array( 'name'=>$name, 'lat'=>$latitude, 'lng'=>$longitude, 'lnk'=>$link );
...
But I'm having problem with the Title/Content of the infowindow.
With the base example I'm using, the content is formatted as a link:
var locations = [
<?php for($i=0;$i<sizeof($locations);$i++){ $j=$i+1;?>
[
'AMC Service',
'<p><?php echo $locations[0]['name'];?></p>',
<?php echo $locations[$i]['lat'];?>,
<?php echo $locations[$i]['lng'];?>,
0
]<?php if($j!=sizeof($locations))echo ","; }?>
];
but the variable pulls only the first link and name from the array, it does not go through the loop. I have tried many different variables, such as
<?php echo $locations[$i]['name'];?>
but this gives an error.
I'm not an expert in either php arrays or loop or java, so I'm fumbling around for clues. I've looked through all of the related questions here for help, and also consulted the Google stack as well.
Any help would be appreciated.
UPDATE:
The first three replies were useful, thank you, but no there yet.
After the comment from Andy, and encouragement from Divyamohan that the original solution should have worked, I realised that there must be some json formatting problem, so I tried:
<?php echo json_encode($locations[$i]['name']);?>
This worked and now I'm able to have these loop through.
But still trying to get this to work as an href link. I tried to solve with backslashes as Hardik and David observed, but still this does not work. Half way there.
'<p><?=$locations[$i]["name"]?></p>'
Just Replace this in your code and it should work.
You need to change this line
'<p><?php echo $locations[0]['name'];?></p>'
to
'<p><?php echo $locations[0][\'name\'];?></p>'
You need to add backslash ( \ ) character to escape quote from string literals.
So finally I found the solution to the problem. Thanks to the comments from everyone that helped me to look at it another way.
In the end, the problem was not with the code. The problem was the data. This should have been obvious. In the links column I had URLs with slashes and text in the names column included apostrophes and foreign characters. These combined were throwing off the json errors. I cleaned all the data and the modified code works perfectly.
<p><?=$locations[$i]['name']?></p>
Many thanks again for the comments.

Simple_HTML_DOM parse 'find' value to Integer

I'm studying Simple_HTML_DOM and I found a problem where I'm working on from 2 hours without finding a solution :-(
I've the following code:
$num = $html->find('span.pageNum');
This code get number of pages on my blog and it works. GREAT.
If I do
echo $num[0];
I see the number of pages on screen, but if I try to do something like:
echo ($num[0]+2);
for example, It doesen't work like an INTEGER and it return me the following output:
3
So, I need to make the "find" to an integer and work for math operations but I tried everything and nothing works (like cast with (int)$num[0] and much more).
Can anyone please help me? I don't know what to do more...I really tried everything!! :-(
Thanks in advance!!
FOUND THE SOLUTION!!
I used:
$pgnum = filter_var($num[0], FILTER_SANITIZE_NUMBER_INT);
worked GREAT!! Thanks :-)

PHP: Use a $_GET-Param with multiple other Params within a $_GET-Param

yeah, I know, the title is kind of confusing, but no better title came to my mind.
Here is my problem:
I want to use a link in my application, which would look like this:
localhost/index?jumpto=some_folder/somescript.php?someparam1=1234&someparam2=4321
The problem is that &someparam2 is meant to hang on the second $_GET-Param.
It would be like this:
localhost/index?jumpto=some_folder/somescript.php?someparam1=1234&someparam2=4321
Instead, PHP interprets that &someparam2 hangs on the first $_GET-Param.
localhost/index?jumpto=some_folder/somescript.php?someparam1=1234&someparam2=4321
Does anyone know a solution for this?
I already tried
localhost/index?jumpto='some_folder/somescript.php?someparam1=1234&someparam2=4321'
but of course that didn't work.
I hope you can understand my problem.
Thank you for your time.
You will need to URL encode your string some_folder/somescript.php?someparam1=1234 so that php will not parse & in the query string as a param separator.
use urlencode("some_folder/somescript.php?someparam1=1234");

Simple if statement not working in wordpress echo is working

I am hoping that someone can help me, I am writing a simple if statement inside WordPress but for some reason it does not seem to execute the way I want it to work.
$g_map = get_the_id().(get_post_meta($post->ID, '_et_business_g_pagetype', true));
if ('map' == $g_map) {
echo "<h1>This is the map page</h1>".$g_map;
}
The if statement is to execute when a Custom Post Meta Field = map
If I execute this line echo get_the_id().(get_post_meta($post->ID, '_et_business_g_pagetype', true)); outside the if statement is does show that the value is "map"
So "map should equal map" and the echo should run as intended, but I cannot understand why it is not...
Any ideas why this maybe happening and how I can fix it will be appreciated.
Do a var_dump($_map); and see what returns it might be a case issue or is doesn't return map. oh and if you want to refactor it to be a little better use === then it won't type cast it but meh it is a string so not much difference.
I have placed the get_the_id() to see if I have the right post! - so infact map did not equal map... it was map = (postnumber)map and this is why the if statement did not work! - Thanks a million for pointing me in the right direction! It is now solved!

PHP Validate Error

Working on a send link to a friend form.
Seeking to provide for defeat spambots by presenting form filler with a code (visitorcode) to imput into a box.
if (trim($_POST ["md5($visitorcode)"] == $_SESSION['image_random_value']))
$errors[] = "<b>Validate Code:</b> ".$form_items["visitorcode"]["error"];
When correct Validate code is installed I want error to clear so that the thanku.html can be presented.I am doing something wrong as it will not work. Can anybody shine a light or give direction?
Full code and problem available at www.shopdemo.webitry.net
I think you want
md5(trim($_POST[$visitorcode]));
I think you meant to type:
if (trim($_POST[md5($visitorcode)]) == $_SESSION['image_random_value'])
or, as PMV mentions:
if (md5(trim($_POST[$visitorcode])) == $_SESSION['image_random_value'])
But either way you misplaced some parentheses and double-quotes in the original code.
EDIT:
It looks maybe like you are dealing with errors in the body of the if clause. That being the case, shouldn't the if statement use != instead of ==? I.e., if they don't match, deal with errors.

Categories