spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » PHP » Page 36
Increase by 10% each time
Look at how you're calculating the house cost: Level 1 = 100 Level 2 = 100 * 1.1 Level 3 = 100 * 1.1 * 1.1 Level 4 = 100 * 1.1 * 1.1 * 1.1 etc. This can be represented with the formula (where ^ is "to the power of"): cost = 100 * (1.1 ^ (level - 1)) You can then express the upgrade cost in PHP as a function of the house level, using pow to calculate the mathematical power: function upgradeC

Categories : PHP

MongoDB on Wamp x64 (win x64) = mongo.native_long error
For me the only thing that worked was: ini_set('mongo.long_as_object', 1); Hope it saves someone's time. It's one of those stupid things that make you wonder: "Why the hell did I become a programmer?" EDIT: getting proper driver from http://pecl.php.net/package/mongo helped me. I've downloaded latest driver. Check your version using phpinfo() command. E.g. for me, on 64-bit Win7 it's: PHP Ve

Categories : PHP

Understanding origin of back slashes in JSON encoded response
PHP's json_encode function is escaping the slashes (see http://php.net/manual/en/json.constants.php for the JSON_UNESCAPED_SLASHES constant you can use if using a recent enough version of PHP). It is perfectly valid JSON to escape slash with a backslash (see the definition of a string on http://json.org/), so your decoder should handle it anyway. The reason to escape a slash is to avoid the char

Categories : PHP

PHP COM Object to Open Word 2013, Count Pages Not Wkg for .docm
Well, doesn't .docm signify that there are macros or event macros present in the file? Usually when the user opens a .docm file, the user is given a security prompt. Being that you are running under PHP, you might be running under a service and the prompt is not being seen in the hidden desktop, or security it preventing it from running at all. I would suggest you write some VBS code to try and

Categories : PHP

Create variable from constant
The variable variable syntax for this case is: define('FOO', 'bar'); $foo = 'baz'; $bar = 42; echo ${FOO}; // 42 Note that this is not necessarily the best approach to i18n, but it answers your direct question. A first step at improving this may simply be to use arrays for starters: $content = [ 'en' => .., 'pl' => .. ]; echo $content[LANG]; The intent and syntax here is much

Categories : PHP

Woocommerce: Payment gateway custom thank you page
I think the filter you need to target is woocommerce_payment_successful_result which is in the WC_Checkout class. function so_27024470_paypal_redirect( $return, $order_id ){ $order = new WC_Order( $order_id ); if( $order->payment_method == 'your-gateway-id' ){ $return['redirect'] = 'http://your-redirect.com'; } return $return; } add_action( 'woocommerce_payment_success

Categories : PHP

Editing User with error wrongly changes the app.user.username temporarily, how to solve it?
This is happening by design. At the moment you call $form->handleRequest($request) the user entity is updated with the submitted form data. When you access app.user you are in fact accessing the same user entity. The docs have some more detail about this

Categories : PHP

Php ssh - Error starting up SSH connection(-1)
Trying to diagnose issues with libssh2 is nigh impossible. My recommendation: use phpseclib, a pure PHP SSH implementation, and assuming that doesn't resolve the issue you can get logs that'll assist in the diagnosis. eg. <?php include('Net/SSH2.php'); define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX); $ssh = new Net_SSH2('www.domain.tld'); if (!$ssh->login('username', 'password')) { e

Categories : PHP

php group array together based on key value being the same
You should use that id_option as the key in your new array, otherwise you're stuck having to hunt through the new array to find where the matching items are, which you're ALREADY doing in the first loop $newarray = array(); foreach($oldarray as $item) { $newarray[$item['id_option']][] = $item; }

Categories : PHP

Keep color output when running scripts on composer
I've just run phpunit via composer and the colors are there. Perhaps the dspec script has no color support or is disabled by default. "scripts" : { "test" : "./vendor/bin/phpunit -c tests/phpunit.xml" },

Categories : PHP

CodeIgniter And Image Display in Table
try print_r($file_data) and see what comes back, you can also try: $file_data['orig_name'] Or: $file_name = $file_data['file_name']; $new_staff = array( 'agenda_id' => $this->input->post('agenda_id'), 't_name' => $this->input->post('t_name'), 'exp' => $this->input->post('exp'), 'leaves_allow_monthly' => $this->input->post('leav

Categories : PHP

Code need to be repeated in php
Provided an even number of icons, something like this would work: <?php $counter = 0; foreach( $icons as $icon ) { if ( $counter % 2 == 0 ) echo '<div class="big">'; ?> <div class="small"> <img src="<?= $icon->src ?>" /> <?= $icon->name ?> </div> <?php if ( $counter % 2 == 1 ) echo '</div>';

Categories : PHP

trying to use query_posts('category_name=page_slug');
The "permalink" of the page it's stored as its post_name, so you can get it from the global $post For instance: global $post; $slug = $post->post_name; $posts_in_cat = query_posts('category_name='. $slug );

Categories : PHP

how to find multidimensional array duplicates in php?
One way to do this would be to keep your own index in another array. If you store each number as a key in your new array, you can then increment that key every time you see it in your array. This should be a reasonably quick approach to this problem. <?php $array = [ ['name' => 'test1', 'number' => '9999'], ['name' => 'test2', 'number' => '9999'], ['name' => 'test3', 'numb

Categories : PHP

database query cuts the end of a long text
You are bumping against the default length limit for GROUP_CONCAT() which is merely 1024 characters. The group_concat_max_len system variable is available for you to increase the limit. Determine what a sensible maximum would be for your application's needs and set the variable for the current session. SET SESSION group_concat_max_len = 65536 No modifications to your code are then necessary.

Categories : PHP

Create thumbnail for display OR Load 50% of image and create image preview
use the following code to create thumb nail images, You can create all type of image file jpeg, png, gif $orig_directory = "$desired_dir"; //Full image folder $thumb_directory = "thumb/"; //Thumbnail folder /* Opening the thumbnail directory and looping through all the thumbs: */ $dir_handle = @opendir($orig_directory); //Open Full image dirrectory if ($dir_handle >

Categories : PHP

Re-direct External .php requests to extension-less URL
This set of directives: # Never Use the naked domain and Remove PHP extension RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC] RedirectMatch 301 /([A-Za-z0-9_-]+).cfm((?.*)|())$ http://www.domain.com/$1$2 RewriteRule ^([A-Za-z0-9_-]+)((?.*)|())$ http://www.domain.com/$1.php$2 [L] Has some problems. The rewrite condition doesn't apply to a RedirectMatch, which isn't even part of mod_rewrite. It's

Categories : PHP

Complex Comments, Tags, Votes, Favorites database relationships using Laravel
here are some of my thoughts I was really confused about whether to use belongsToMany vs morphToMany. But now as I get more familiar with Laravel, it becomes clear to me that what morphToMany can do can be done by belongsToMany too. So you need only master belongsToMany. It's powerful enough. However, if you want to know the difference between the two relationships, here's the explanation on whe

Categories : PHP

Masked html redirect to php stays unmasked
If www.siteA.com and www.siteB.com are on different hosts, the only way to get the content on www.siteB.com to be served while the browser's URL address bar says www.siteA.com is to request the content on behalf of the browser. You can do this either by setting up a proxy using apache or maybe an iframe. <!doctype html> <html> <head> <title>My Site</title&g

Categories : PHP

fineUploader deleting a file
As described in the delete file endpoint handler section of the docs: Handle the POST or DELETE at your specified endpoint Locate the file based on the file UUID included in the path of the request. Delete the file.

Categories : PHP

PNG transparency issue
Your image is palette-based, not true colour, so the calls to imagealphablending() and imagesavealpha() aren't needed. The simplest way to do this is to replace the pink colour in the palette-index with a transparent one, like so: $file = 'image.png'; $im = imagecreatefrompng($file); $new = imagecolorclosest($im, 255, 0, 255); imagecolorset($im, $new, 255, 0, 255, 127); header('Content-type:

Categories : PHP

Best way to have a variable template in php
Try this: //list of menu headers $headers = new array(); //populate the array with your headers here ... foreach($headers as $val) { if( $PageTitle == $val ) echo '<li class="active"><a href="#">'.$val.'</a></li>'; else echo '<li><a href="#">'.$val.'</a></li>'; }

Categories : PHP

Failed opening required 'System.php' (include_path='.;C:phppear') in D:wampwwwz
In WAMPServer, the include_path is commented out, so you are getting the default version which is why it is pointing to include_path='.;C:phppear' So you could try editing the php.ini file, using the wampserver menus to make sure you edit the correct file (wampinphp{phpVersion}inphpForApache.ini) wampmanager->PHP->php.ini And add a proper include path in place of the commented out one

Categories : PHP

Disable AJAX on checkout for WooCommerce
All WooCommerce strings are properly localized with wp_localize_script so I would think you could correctly translate them by creating the appropriate .po/.mo file, but I confess to not having a lot of experience with translations. For reference: all available language packs are at Github and you might also want to read the documentation. Anyway, the checkout scripts are all in checkout.js. Like

Categories : PHP

all possible subtrings php
Here is what I whipped up - function get_all_subs($input) { $arr = str_split($input); $all_subs = array(); for ($i = 0; $i < count($arr); $i++) { for ($j = $i; $j < count($arr); $j++) { $all_subs[] = implode('', array_slice($arr, $i, $j - $i + 1)); } } return $all_subs; } $input="KRKRK"; $substrings = get_all_subs($input); print_r($su

Categories : PHP

Wordpress if/else statement on archive page
This is an easy one: You shouldn't echo the_permalink() and the_title() as they already echo their respective results: <?php if ( is_category( 'producten-diensten' ) ) { echo' the code for producten-diensten category '; } else { //everything else while ($wp_query->have_posts()) : $wp_query->the_post(); echo'<article class="col-sm-3 col-6 portb

Categories : PHP

Seemingly identical sql queries in php, but one inserts an extra row
Using your $_POST directly in your query is opening you up to a lot of bad things, it's just bad practice. You should at least do something to clean your data before going to your database. The $_POST variable often times can contain additional values depending on the browser, form submit. Have you tried doing a null/empty check in your foreach? !~ Pseudo Code DO NOT USE IN PRODUCTION ~! foreac

Categories : PHP

Warning: number_format() expects parameter 1 to be double, string
You're trying to format an string as a number, which will not work. Can you post the value of $item['c'] so we can see what sort of data we will see? Or better yet, post the value of $item.

Categories : PHP

PHP Array with soap
You have a multi-dimensional array structure here. There are 2 levels of nesting. AuthenticateCustomerResult is a scalar value 0, but aCustomerArray is itself an array with one element whose key is called UDT_Cpower_CustomerInfo. It's in there you'll find all the properties you want. For example: // Assuming $result is the outermost Array structure you posted above. $CustomerKey = $result['aCust

Categories : PHP

error "array to string conversion" in FacebookCurl.php
Looks like in the $custom_image just the path to the image is required but you are assigning the whole $_FILES[] compound array to it. Try replacing this line $custom_image=$_FILES['custom_image']; in your code with this, $custom_image=$_FILES['custom_image']['tmp_name']; and see if it works

Categories : PHP

Specific handling for an additional 3rd file upload in Codeigniter
(Actually half) Solved! when you upload files, the $_FILES superglobal generates entries for each of those files, even if you don´t upload them, so, echoing $field, I found I can use that key to assign file types as follows: foreach($_FILES as $field => $file){ if($field != "file3"){ $config["allowed_types"] = "txt|pdf|gif|jpg|png|tiff|doc|docx|rtf|jpeg"; }e

Categories : PHP

Using php, how to get return object data into variable?
You can as well return the array itself, and then traverse the array using for loops, maybe something like this public function method_y(){ ..... code does stuff ..... return $array; } $var = $x -> method_y(); foreach($var as $element) { foreach($element as $key => $value) { echo $key; echo $value; } }

Categories : PHP

Dynamically inserting a bootstrap modal partial view into a view
You can do this in any point into a view where you need to load the 'partial' view. $this->load->view('modal_view'); EDIT: Load dynamic content In this example I will use an jQuery AJAX call to retrieve the view dynamically. In your view you have to include a target div to insert the AJAX response. <div id="modal_target"></div> The button to load the modal and show. <

Categories : PHP

Get master request in Symfony 2.4
http://api.symfony.com/2.4/Symfony/Component/HttpFoundation/RequestStack.html From the RequestStack you can get the master request $stack->getMasterRequest(). The request as a service is deprecated $this->container->get('request'), but this stack replaced it.

Categories : PHP

when i add new comment the delete button doesn't work till i reload the page?
Correct. That is because theres no event on that new button. Maybe like this: var deleteButton = function() { $(".delete_buttom").off('click'); $(".delete_buttom").on('click', function() { var x = $(this).attr('id'); click_delete(x); }); } Now, in your success (after you added the new entry): success(function(data) { // add your entry... deleteButton

Categories : PHP

How can achieve a clean URL redirect
yes you can redirect (that is: set/reset/unset any header you want) as long as no output happend before (none, not even whitespace or BOM (utf-8 byte order mark) - iirc) in case you have output you can capture it via ob_start and output if afterwards oddly enough: this is even made quite clear in the doc

Categories : PHP

woocommerce change continue shopping link in cart
You may try add below code into your theme functions.php: function custom_woocommerce_continue_shopping_redirect( $return_to ) { return get_permalink( woocommerce_get_page_id( 'shop' ) ); } add_filter( 'woocommerce_continue_shopping_redirect', 'my_woocommerce_continue_shopping_redirect', 20);

Categories : PHP

Controlling an interactive process with PHP using Symfony Process
Finally found a solution to this problem after reading the source for ssh-add and by reading this very old article from Wez Furlong where he talks about adding PTY support to PHP. To quote the article: What this does is similar to creating a pipe to the process, but instead creates master (for your script) and slave (for the process you're running) pty handles using the /dev/ptmx interface of

Categories : PHP

Parsing 2 head json and grouping using php
I have fixed the code http://codepad.org/vLhzs6kJ#output $string = '{ "status": { "message": "success", "code": 200 }, "clients": [ { "values": [ { "Code": "rdf", "name": "first" }, { "Code": "fg", "name": "second"

Categories : PHP


Recently Add
Extracting sentences from text based on particular pattern
How to include tags in createNotification in PushApps api?
clarification on $_Files php command
Multiple where clause on Eloquent ORM Laravel
How to get the value in field by new line and update into the column in table with same id in php mysql?
Accessing session data in other method in same controller is not working in codeigniter
Bootstrap button, how to click multipite times
How to use __autoload function when use composer load
Not sure how to handle a fairly involved query with PHP/MySQL
Regex for detecting a word enclosed but in order
Using wpdb to search usermeta values
Codeigniter Multi Insert Query
exec() error, i cant figure it out how to make it work
how to Remove array and created new array in php
Proxy server in php
Cannot install YOURLS (PHP Parse error: syntax error, unexpected ';', expecting ')' in config.php on line 66)
Codeigniter if id = 1 it's work multiple image update but id =2 it's not working
How to add more than one tabs to a single facebook page by sdk in php
php server parse simple string using JSON to Android client
Mysql - most optimal way (performance and scalability) to store and retreive multiple lines of text
Break one array in to two different array in php
remove quotes from criteria params
CodeIgniter query result (class) includes non-property fields
How to delete the original image after resizing it
Sorting An Array By Key Value
PHP function On Each Page Causes Redirect Loop
Split date ranges into corresponding weeks
codeigniter do_upload is missing argument 1 on ubuntu server
Comparing only dates From the database Timestamp Laravel
Changing an individual foreach array field tag input type
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.