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;
}
Related
i am getting some html code from database. It will be stored with few PHP defines. which are defined in a previous function where the current function will return the html code from database.
How can i get the define value inside the html code revived from database.
The defines you see has been declared in the data which i am getting from database. But i am unable to get their values. It is not dynamically getting the define value in $thankYouTemplate
function newPostPageMailDesign($title, $feturedImage, $smallContent, $permalink, $youMayAlsoLikeQuery) {
define('featuredImage', $feturedImage);
define('shortContent', $smallContent);
define('permalink', $permalink);
define('title', $title);
$thankYouTemplate = getData();
$HtmlAMiler = $thankYouTemplate;
return $HtmlAMiler;
}
function getData()
{
$Data = "Some HTML Code from database with".featuredImage.permalink."already in the databse";
return $Data;
}
Edit your HTML code in your database by adding a dummy string e.g "__DUMMYSTRING__". Now using str_replace replace the "__DUMMYSTRING__" with the content or HTML Code you wish to add.
example:
echo str_replace( '__DUMMYSTRING__' , $newHTMLCODE, $HTMLCodeFormDataBase);
May not be the efficient way but may work.
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);
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 have a function, that check user language and write it down in a variable. After a time, i come of idea to merge they, so that i need a call the function anytime before the first use of a variable, so i put a call of function inside of var, with a idea, that i would be replace it self. But it does not working, becouse it trying to give me a "Closure Object" back, i think it is a function in clear and not the result :( Here is the important part of code:
$GLOBALS['user_language'] = function()
{
return get_user_language();
}
function get_user_language()
{
$user_language = 'en';
$GLOBALS['user_language'] = $user_language;
return $user_language;
}
//somewhere in the script
print_r($GLOBALS['user_language']);
I wish to get 'en' out, nothing more.
function get_user_language()
{
$user_language = 'en';
$GLOBALS['user_language'] = $user_language;
return $user_language;
}
$GLOBALS['user_language'] = get_user_language();
//somewhere in the script
print_r($GLOBALS['user_language']);
But this is strange because you set it already in get_user_language() then you pull it again. It would almost create a loop. The proper way would probably be to remove the $GLOBALS['user_language'] = $user_language; from the function.
Hope this answers your question.
Just use print_r(get_user_language()) instead of print_r($GLOBALS['user_language']);.
If getting the user's language multiple times would be particularly slow (e.g. a database query would be executed over and over again), you can do something like this:
function get_user_language()
{
static $user_language = null;
if ($user_language === null) {
$user_language = 'en'; // this would be where you make the DB query
}
return $user_language;
}
In practice, in a large PHP application, this code would generally be located in a class and would store the value as an object property, so that, for example, the application can cache DB query results for multiple users rather than for only the current one.
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);
}