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
Related
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;
}
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);
This is kind of a stupid question but I'm in doubt:
I'm checking below that a function (which queries my db) doesn't return NULL and redirecting if it does.
If it doesn't I then assign it to an array.
In the code below, is the query ran twice?
if (!$this->review_model->GetReview($data['review_type'], $data['review_id'])) {
redirect();
}
$data['review'] = $this->review_model->GetReview($data['review_type'], $data['review_id']);
Yes, it runs twice if not redirected...
Do this
$data['review'] = $this->review_model->GetReview($data['review_type'], $data['review_id']);
if (!$data['review']) {
redirect();
}
For your question, No, once redirect() method called, further line not executed.
But your checking is not good. you can change it is as following
$data['review'] = $this->review_model->GetReview($data['review_type'], $data['review_id']);
if(!$data['review']){
redirect();
}
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 am using the great tutorial provided by Nodstrum. I am attempting to autofill multiple text fields with PHP, MYSQL, and AJAX. I have a PHP script, here is the line of code returning my results:
echo '<li onClick="fill(\''.$result->name.'|'.$result->id.'\');">'.$result->name.'</li>';
Notice that I am seperating my results with a pipestem character.
Here is the function where I am receiving the error 'Undefined or not an object' I am breaking out the values and using the pipestem as splitting the values from mysql.
function fill(thisValue) {
myvalues=thisValue.split('|') {
$('#inputString').val(myvalues[0]);
$('#email').val(myvalues[1]);
}
window.setTimeout("$('#suggestions').hide();", 200);
}
If I 'ok' the error messages, I will eventually see both values displayed in the text fields, so I believe I am retreiving the values properly from MySQL. I appreciate any help anyone can provide to get me steered in the right direction, or a fresh perspective.
Thanks Again,
--Matt
The value you are passing that becomes thisValue is null or undefined. You can test this parameter before blindly trying to .split it (the split function works only on strings).
function fill(thisValue) {
// "value" will always be a string
var value = thisValue ? String(thisValue) : '';
// this line will not generate an error now
var myvalues=value.split('|');
// but these ones might! make sure the length of myvalues is at least 2
if (myvalues.length >= 2) {
$('#inputString').val(myvalues[0]);
$('#email').val(myvalues[1]);
}
// this might need to go inside the above if
window.setTimeout("$('#suggestions').hide();", 200);
}
Try this:
function fill(thisValue) {
myvalues=thisValue.split('|');
$('#inputString').val(myvalues[0]);
$('#email').val(myvalues[1]);
window.setTimeout("$('#suggestions').hide();", 200);
}