this is my first post. So basically I am trying to make a php file that returns the value of a website.
Here's what I got so far:
<?php
function GetRank($userId,$groupId) {
$url = "http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=GetGroupRank&playerid=$userId&groupid=$groupId";
//echo $userId,$groupId;
//$response = readfile($url); // works but returns this (READ HERE)'<Value Type="integer">1337</Value>32'
if ($response) {
return $response;
}
return 'Failure';
}
?>
<Value Type="integer">1337</Value>32
I don't want to have it returning the above, as it currently does, I wanted it to return 1337. No clue how, I never did this before.
An example link:
http://www.roblox.com/Game/LuaWebService/HandleSocialRequest.ashx?method=GetGroupRank&playerid=25608009&groupid=228876
Thanks in advance I hope u guys understand me q.q
You can use the function below which will remove html tags from a string.
strip_tags($response);
Related
I've been trying for 3 days to get PHP to show the ID from this test JSON using PHP and httpful.
Anyone have any ideas as i've tried loads of different combinations and even tried created a handler to decode as an array... I just suck at PHP ?
// Make a request to the GitHub API with a custom
// header of "X-Trvial-Header: Just as a demo".
<?php
include('\httpful.phar');
$url = "https://jsonplaceholder.typicode.com/posts";
$response = Httpful\Request::get($url)
->expectsJson()
->send();
echo "{$response[0]['id']}";
?>
My output... still nothing
You are not properly indexing the return value.
The response is a mixed value. So you should do something like below to get what you are looking for.
<?php
include('\httpful.phar');
$url = "https://jsonplaceholder.typicode.com/posts";
$response = Httpful\Request::get($url)
->expectsJson()
->send();
echo $response->body[0]->id;
?>
i want to replace a string with database function if it exists. i am using str_replace in following way but it doesn't work for me, this is returning $numOne as it was. i am beginner in php so help me
function stringreplace($multiple,$numOne){
$multiple=Multiply;
$numOne=a_b_cMultiply;
str_replace($multiple,"abcdfgh('','')::numeric",$numOne);
return $numOne;
}
Your code is not correct as you are not storing the result anywhere and also you are returning $numOne which contains the old value . Use this code:
function stringreplace($multiple,$numOne){
$multiple='Multiply';
$numOne='a_b_cMultiply';
$num_one = str_replace($multiple,"abcdfgh('','')::numeric",$numOne);
return $num_one;
}
Long short, I have a function that is responsible for executing specific data from my database, but the problem is I can't use that function. To be more clear:
This is the function
function ReplaceHTMLCode_Database($content){
$content = str_replace('{SELECT_CHAR}',GetPlayerSelect(),$content);
}
function GetPlayerSelect(){
$QUERY = mysqli_fetch_array(mysqli_query( ConnectiShopDb(),
"SELECT * from ".ISHOP_MYSQL_DB.".select_char where account_id=('".$_SESSION['ISHOP_SESSION_ID']."')"
));
if($QUERY['pid_id']){
return GetPlayerInfo($QUERY['pid_id'],'name').
"(".GetPlayerRaceByJob(GetPlayerInfo($QUERY['pid_id'],'job')).")";
} else {
return "{NO_CHARACTER_LABEL}";
}
}
I hope that I'm not being vague, But I tried selected="selected">{"SELECT_CHAR"}</option> in my PHP form that is supposed to be displaying this function and it's just being displayed as $SELECT_CHAR. I'm aware that this may be part of WordPress code since
I googled how to use ReplaceHTMLCode_Database and figured out it's pretty much something to do with WP, but I'm not using WordPress or any different CMS. Any help is so much appreciated!
Your function isn't returning or changing the variable. It would need to either do this:
function ReplaceHTMLCode_Database(&$content){
$content = str_replace('{SELECT_CHAR}',GetPlayerSelect(),$content);
}
This takes the variable by reference and changes it. You could then use it like so:
ReplaceHTMLCode_Database($content);
Otherwise, you could do this:
function ReplaceHTMLCode_Database($content){
return str_replace('{SELECT_CHAR}',GetPlayerSelect(),$content);
}
Which returns a new value that you could assign somewhere, like this:
$content = ReplaceHTMLCode_Database($content);
Your ReplaceHTMLCode_Database doesn't return anything. Could it be a simple
function ReplaceHTMLCode_Database($content){
return str_replace('{SELECT_CHAR}',GetPlayerSelect(),$content);
}
Please give some information about what the function should do.
I thought this would be easy, but some reason it is not work
public function test($data = null){
}
but when I want to send some data to the function it turns it to null so how can i have it so that if i dont send anything it is null otherwise it the data I sent
function test($data = null){
echo $data;
}
test('abcd'); // output abcd
see working example http://codepad.viper-7.com/Z8T23k
that looks about right for optional parameter syntax. We'll have to have more details to tell you what is not working
I use the latest code igniter (2.0.3) and php-active 0.0.1.
All are working fine except save();
Code:
if($_POST)
{
$entry= Customers::find_by_routeid('4');
$entry->routeid=5;
$entry->save();
}
Here's my problem: for some reason that I cannot understand the above code does not work, but if I take the code out of if ($_POST), it works fine.
What I am doing wrong?
EDIT:
Thanks Damien Pirsy $this->input->post() does the trick, but when I uncomment the comments in the code the problems returns.
The code now is:
if($this->input->post())
{
$id = $this->input->post('id');
$oldRoute = $this->input->post('oldRoute');
$newRoute = $this->input->post('newRoute');
$entry= Customers::find_by_routeid($this->input->post('oldRoute'));
$entry->routeid=$this->input->post('newRoute');
$entry->save();
/*
if($oldRoute<$newRoute)
{
for ($i=$newRoute; $i>$oldRoute; $i--)
{
$element = Customers::find_by_routeid($i);
echo $element->routeid -= 1;
$element->save();
}
}
*/
}
The elements new IDs ($element->routeid -= 1;) are echoing right, but I have the same problem as in the beginning and neither of two saves work.
You didn't provide much details or debug info, so I'll just guess: try using the CI's native post handler instead. You should have var_dump()ed the $_POST array, see if isset() or not, also, since you're using it as a condition
if($this->input->post())
{
//...
}
UPDATE:
Since we're talking about Post variables, don't assume they're exactly as you want them. Keep in mind that $this->input->post('field') returns FALSE when the index is not present; that might well brake your if condition.
Assuming you need numbers to do this, you can do a check like
if($this->input->post('newRoute') AND is_numeric($this->input->post('newRoute'))
{
$newRoute = $this->input->post('newRoute');
}
else
{
// give it a default value, or raise an error, for example. If you need this
// variables, and need them to be numbers, you cannot go on in case these
// conditions are not met, right?
}
And the same for $oldRoute.
And yeah, OK, maybe you can write a cleaner code than mine, but you get the picture ;)