please somebody help me make this correct. I have no knowledge in php
echo bowob_api_get_code(/* BOWOB_APP_ID */, /* BOWOB_SERVER_ADDRESS */);
am supposed to substitute values BOWOB_APP_ID with somevalue 67890 and BOWOB_SERVER with http://euwest1.bowobcloud1.com/
I did it as shown below, but i keep getting error on this line
echo bowob_api_get_code('67890, http://euwest1.bowobcloud1.com/ ');
As it is right now, you have a single string argument, whereas you need an integer and a string.
echo bowob_api_get_code(67890, "http://......./");
Related
I'm trying to mix <?php echo do_shortcode('[...]') with a field from Advanced Custom Fields within Wordpress.
So basically what I'm trying to do is give the user a text field in the page edit screen where she can paste in the ID of a youtube vide. This field will then update my do_shortcode to display the correct video.
I'm not sure what I'm doing wrong considering I've done this several times before and been succesful. I do have a feeling I'm not escaping the string correctly?
<?php echo do_shortcode('[video_lightbox_youtube video_id="' . the_field("youtube_video") . '" width="640" height="480" anchor="Play Video"]'); ?>
Anyone able to lead me in the right direction? :)
EDIT
The code above returns q_cHD1lcEOo with multiple spaces in front of it as well as this: "Error! You must specify a value for the Video ID, Width, Height parameters to use this shortcode!" That's why I was thinking I'm not escaping it correctly as these are all specified.
I'll add that if I remove the_field("...") and replace it with just an ID it displays perfectly.
SECOND EDIT
Since I was not supposed to echo it, I was using the wrong function to get the field. Instead of using the_field() which prints the value, I was supposed to use get_field() to simply return it to the string.
Your question is somewhat unclear, but I'm also 20 hours without sleep.
Anyways, as far as mixing PHP within a PHP string, there's numerous ways to do it..
You can use concatenation or { } within the string itself.
For example, say we want to echo out the property of an object within a string.
We could do the following
echo "This is my property " . $object->property;
Or, we can do this
echo "This is my property {$object->property}";
You can even do cool things like access associative arrays within strings like so
echo "This is my property {$object->property['cool']}";
Hopefully this leads you in the ride direction.
At first glance it looks like you should be using get_field instead of the_field. the_field will print without being prompted, whereas get_field will return its value, which is what you want.
I see you've also mentioned whitespace at the start, you should consider wrapping the function in trim.
See below:
<?php echo do_shortcode('[video_lightbox_youtube video_id="' . trim(get_field("youtube_video")) . '" width="640" height="480" anchor="Play Video"]'); ?>
I am getting a variable from a socket. After reading the respond I am trying to convert the value to a number. if I print the respond it looks correct however when I convert it to number using floor() it doesn't give me the right answer. I also tried to print the length of the variable and it is still not working as it suppose to: This one is for value :185
echo("**************** ".floor($res[0]));
echo "################### $res[0]";
echo "------------- ".strlen($res[0]);
output:
**************** 1################### 185------------- 12
I have also tried stripslashes, trim and also ereg_replace('[:cntrl:]', '',$res[0])
Please try the following: intval($res[0])
You can try also with:
$res = (int)$reg[0];
Hope this helps.
Bye
Ok I found the problem. I saved the value in a file and opened the file using notepad++. I saw the following character in between my string:
SOH,NULL, and bunch of other non character values
What I am assuming is PHP automatically ignore the ASCII values are not show able on the screen (less than 21Hex).
I'm a total newbie with php. I'm returning some variables for an address and am checking to see if an address2 exists. If it's null, I want it to skip and not put an extra line in the formatting. But, it seems to be breaking the line anyway. I've experimented with break tags all over the place and not, but can't find where it's coming in.
echo "$comp_name<br>$comp_add1";
if (isset($comp_add2)) {
echo "<br>$comp_add2"; }
echo "<br>$comp_city, $comp_state $comp_zip<br><a href=\"http://$comp_url\" >$comp_url</a>";
Take a look at this page: http://projects.ekcetera.com/people.php ... click on ABC Company, then check A Simplified Life, you'll see the extra line break in A Simplified Life.
What am I missing?
Your example page shows a fatal error, but I assume you have to use empty here, because the variable might be set, but only filled with an empty string.
So
if (isset($comp_add2)) {
echo "<br>$comp_add2";
}
should be
if (!empty($comp_add2)) {
echo "<br>$comp_add2";
}
Here is a good explanation regarding isset vs empty:
http://www.virendrachandak.com/techtalk/php-isset-vs-empty-vs-is_null/
in A Simplified Life your $comp_add2 is set , you must check is it null or not
echo "$comp_name<br>$comp_add1";
if (!empty($comp_add2)) {
echo "<br>$comp_add2"; }
echo "<br>$comp_city, $comp_state $comp_zip<br><a href=\"http://$comp_url\" >$comp_url</a>";
First I have these variables:
$asd=$current[0]->icon['data']; // -it will print /ig/images/weather/mostly_cloudy.gif
$icons["/ig/images/weather/rain.gif"][0]; // it will print rain.gif
I want to see rain.gif output. I'm trying to do this.
echo $icons[$asd][0]; // I will get error.
I want to get this output with variables.
$icons["/ig/images/weather/rain.gif"][0]; // it will print rain.gif
Is the code wrong?
echo $icons[$asd][0];
Please help.
thanks evryone. sorry for my english.
how can I do this.
I think you're looking for basename.
echo basename('/ig/images/weather/mostly_cloudy.gif'); // output: mostly_cloudy.gif');
echo basename('/ig/images/weather/rain.gif'); // output: rain.gif
Assuming that $asd (in your example) is the path to the image and you're just looking for the file name portion).
Though your question is not 100% clear.
I have a string that has HTML & PHP in it, when I pull the string from the database, it is echo'd to screen, but the PHP code doesn't display. The string looks like this:
$string = 'Hello <?php echo 'World';?>';
echo $string;
Output
Hello
Source Code
Hello <?php echo 'World';?>
When I look in the source code, I can see the php line there. So what I need to do is eval() just the php segment that is in the string.
One thing to consider is that the PHP could be located anywhere in the string at any given time.
* Just to clarify, my PHP config is correct, this is a case of some PHP being dumped from the database and not rendering, because I am echo'ing a variable with the PHP code in it, it fails to run. *
Thanks again for any help I may receive.
$str = "Hello
<?php echo 'World';?>";
$matches = array();
preg_match('/<\?php (.+) \?>/x', $str, $matches);
eval($matches[1]);
This will work, but like others have and will suggest, this is a terrible idea. Your application architecture should never revolve around storing code in the database.
Most simply, if you have pages that always need to display strings, store those strings in the database, not code to produce them. Real world data is more complicated than this, but must always be properly modelled in the database.
Edit: Would need adapting with preg_replace_callback to remove the source/interpolate correctly.
You shouldn't eval the php code, just run it. It's need to be php interpreter installed, and apache+php properly configured. Then this .php file should output Hello World.
Answer to the edit:
Use preg_replace_callback to get the php part, eval it, replace the input to the output, then echo it.
But. If you should eval things come from database, i'm almost sure, it's a design error.
eval() should work fine, as long as the code is proper PHP and ends with a semicolon. How about you strip off the php tag first, then eval it.
The following example was tested and works:
<?php
$db_result = "<?php echo 'World';?>";
$stripped_code = str_replace('?>', '', str_replace('<?php', '', $db_result));
eval($stripped_code);
?>
Just make sure that whatever you retrieve from the db has been properly sanitized first, since you're essentially allowing anyone who can get content into the db, to execute code.