PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
joinnavdev
Forum Newbie
Posts: 21 Joined: Thu Feb 05, 2015 2:34 pm
Post
by joinnavdev » Tue Sep 27, 2016 12:04 pm
Hi All,
I am new to php & got struck with below notice/warning i.e. array to string conversion. Please find the below code, any help or suggestion in resolving the notice/warning would be great help........
I knew we can suppress the warning but want a solution the below notice/warning...
::::::CODE::::::
Code: Select all
$arrUrl=array();
foreach($_GET as $k=>$v)
{
if($k=="attachmentID") continue;
if($k=="m")
{
$k="return_m";
}
else if($k=="a")
{
$k="return_a";
}
$arrUrl[]="{$k}={$v}";
}
$url=implode("&",$arrUrl);
Notice: Array to string conversion at line $arrUrl[]="{$k}={$v}";
Thanks,
Nick
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Tue Sep 27, 2016 12:52 pm
One of those two variables is an array. I won't tell you which one. To fix the problem you should... well, I would say you should ditch the entire thing and do
Code: Select all
$qs = $_GET;
if (isset($qs["attachmentID"])) {
unset($qs["attachmentID"]);
}
if (isset($qs["m"])) {
$qs["return_m"] = $qs["m"];
unset($qs["m"]);
}
if (isset($qs["a"])) {
$qs["return_a"] = $qs["a"];
unset($qs["a"]);
}
$url = http_build_query($qs);
instead because using a loop to do this is silly.
joinnavdev
Forum Newbie
Posts: 21 Joined: Thu Feb 05, 2015 2:34 pm
Post
by joinnavdev » Thu Sep 29, 2016 4:31 pm
HI,
First of all really thanks for your help in resolving the issue.
Your modified code really helped a lot but got struck further with same issue....
http://www.rhats.com/index.php?m=search ... SearchOn=0
Trying to extract bulk_resume parameter but getting array to string.....
$bulk_resume_url="";
if(isset($GET["bulk_resume"]))
{
$bulk_resume_url="&bulk_resume=".$_GET["bulk_resume"];
}
One more time again your help will be highly appreciated. I knew this might be basic for a guy like me who is new to php is tough one to crack it....Hope you understand ....
Thanks,
nick
joinnavdev
Forum Newbie
Posts: 21 Joined: Thu Feb 05, 2015 2:34 pm
Post
by joinnavdev » Thu Sep 29, 2016 5:05 pm
Hi,
While using your earlier suggestion...special character being added...
$qs = $_GET;
if (isset($qs["attachmentID"])) {
unset($qs["attachmentID"]);
}
if (isset($qs["m"])) {
$qs["return_m"] = $qs["m"];
unset($qs["m"]);
}
if (isset($qs["a"])) {
$qs["return_a"] = $qs["a"];
unset($qs["a"]);
}
$url = http_build_query($qs);
bulk_resume%5B%5D=2 is being built instead of bulk_resume=2
Is there any function in php which removes special character...
Thanks,
Nick
joinnavdev
Forum Newbie
Posts: 21 Joined: Thu Feb 05, 2015 2:34 pm
Post
by joinnavdev » Thu Sep 29, 2016 5:26 pm
Hi,
I am sorry for too many post but after research got to know new things and wanted to share the code because of which extra character is coming....
<input type="radio" name="bulk_resume[]" value="1" <?php echo ($checkedSearchOption == 1) ? "checked":"" ?> />
<input type="radio" name="bulk_resume[]" value="2" <?php echo ($checkedSearchOption == 2) ? "checked":"" ?> />
<input type="radio" name="bulk_resume[]" value="3" <?php echo ($checkedSearchOption == 3) ? "checked":"" ?> /> Search <b>OVERALL</b> Resume
As I amusing [] reserver character so %5B%5D is there anyway to remove from URL?????
Once again sorry for too many replies...
Thanks,
Nick
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Thu Sep 29, 2016 10:48 pm
Don't name it with the []s.