logo
down
shadow

PHP - preg_replace how to add an extra "]" and an extra "["


PHP - preg_replace how to add an extra "]" and an extra "["

By : user3042254
Date : November 27 2020, 05:23 PM
around this issue A couple of possibilities:
The string is valid JSON, whether it was intended to be or not, so you can decode it, chunk the resulting array and re-encode it.
code :
$result1 = json_encode(array_chunk(array_column(json_decode($string),0),2));
$result2 = preg_replace('/(\d+)\D+(\d+)/', '$1,$2', $string);
preg_match_all('/\d+/', $string, $numbers);
$result3 = json_encode(array_chunk($numbers[0], 2), JSON_NUMERIC_CHECK);


Share : facebook icon twitter icon
"SELECT TOP", "LEFT OUTER JOIN", "ORDER BY" gives extra rows

"SELECT TOP", "LEFT OUTER JOIN", "ORDER BY" gives extra rows


By : user1824112
Date : March 29 2020, 07:55 AM
I hope this helps you . I have the following Access 2002 query I'm running through OLE DB in .NET: , When I also ORDER BY tblClient.Client the query appears to work:
code :
SELECT  TOP 25
        tblClient.ClientCode,
        tblRegion.Region
FROM    (tblClient LEFT OUTER JOIN
            tblRegion ON tblClient.RegionCode = tblRegion.RegionCode)
ORDER BY tblRegion.Region, tblClient.Client
replacing "span" tag with "input" tag results in displaying of extra "<" and ">

replacing "span" tag with "input" tag results in displaying of extra "<" and ">


By : BasedChinChin
Date : March 29 2020, 07:55 AM
To fix this issue You didn't set your delimiters, and your strings are not properly escaped. It works if you do that, e.g.
code :
$oldstr1='/\<span style="font-family: Times New Roman; font-size: 12pt;"\>/';
$oldstr2='/\<\/span\>/';
Conditional .htaccess 301 redirect when file name contains "extra" and ".php" and "id=XYZ"

Conditional .htaccess 301 redirect when file name contains "extra" and ".php" and "id=XYZ"


By : user2232481
Date : March 29 2020, 07:55 AM
it fixes the issue I am a non-technical person so kindly bear with me.
code :
RewriteCond %{QUERY_STRING} ^view=article&id=(?:[0-9]{1,3}|1000)(&|$) [OR]
RewriteCond %{QUERY_STRING} ^view=article&id=(668)&action=synopsis [OR]
RewriteCond %{QUERY_STRING} ^view=person&id=1
RewriteRule ^(?:index\.php|)$ http://www.innovateonline.info? [R=301,L]

RewriteCond %{QUERY_STRING} ^id=1149(&|$) 
RewriteRule ^extra\.php$ http://www.innovateonline.info? [R=301,L]
Perl: do-while loop over number of keys in a "growing" Hash of Arrays produces "extra" output

Perl: do-while loop over number of keys in a "growing" Hash of Arrays produces "extra" output


By : Dedi2
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I am not sure if I have made it perfectly clear in the title, but my problem is as such: I have do-while loop that takes an initialized hash of arrays (HoA), computes a new dimensional array, and then compares the generated array with the array associated with the array's of each key (for simplicity the keys are numeric...so maybe better to just do this as an array of arrays). If certain crietria are fit (e.g. the new values are within a particular "distance") a new key is generated for the HoA and the generated array is added to the HoAs with the new key. , Following the advice of @Schwern I went back and looked at the
code :
foreach $element (keys %dist){ ...
foreach $element (keys %dist){
    $HoA{$element}[3]++;
    my $newKey=scalar (keys %HoA);
    if($newKey!=($PolymerSize-1)){
        push @{$HoA{$newKey}}, $coordsNeighbors[0];
        push @{$HoA{$newKey}}, $coordsNeighbors[1];
        push @{$HoA{$newKey}}, $coordsNeighbors[2];
        push @{$HoA{$newKey}}, $coordsNeighbors[3]+1;
        push @{$BondHoA{$element}}, "$newKey";
        push @{$BondHoA{$newKey}}, "$element";
       #here I add a last to break out and go to the next do-while iter.
        last
    }
#!/usr/bin/perl;
use strict;
use warnings;
use Data::Dumper;
my $PolymerSize=8;
my $maxNeighbors=3; #each monomer/node can bond upto 3 times
my %HoA; #Store coordinates and number of neighbors for each monomer/node (in C would be an array of structs)
my %BondHoA; #who are my neighbors
my @coordsNeighbors;
my $element; #Iteration dummy variable
my %dist; #temporary distance hash
my $selected;
$coordsNeighbors[0]=0; #Xcoord
$coordsNeighbors[1]=0; #YCoord
$coordsNeighbors[2]=0; #ZCoord
$coordsNeighbors[3]=$maxNeighbors; #How many bonded neighbors?
my $tempx;
my $tempy;
my $tempz;
my $tempL1;
#Intialize origin (first node/monomer)
push @{$HoA{0}}, $coordsNeighbors[0];
push @{$HoA{0}}, $coordsNeighbors[1];
push @{$HoA{0}}, $coordsNeighbors[2];
push @{$HoA{0}}, $coordsNeighbors[3];
my $iter=0;
#Generate new nodes/monomer and "grow" polymer
do{
 #print "$iter\n";
 # $iter++;
  undef(%dist);
        for(my $j=0;$j<3;$j++){
             $coordsNeighbors[$j]=int($PolymerSize*rand()); #generate coords of potent. monomers/node
         }
             $coordsNeighbors[3]=$maxNeighbors;
        foreach $element ( keys %HoA) { #loop through existing monomers/nodes
                $tempx=int($HoA{$element}[0])-int($coordsNeighbors[0]);
                $tempy=int($HoA{$element}[1])-int($coordsNeighbors[1]);
                $tempz=int($HoA{$element}[2])-int($coordsNeighbors[2]);
                $tempL1=abs($tempx)+abs($tempy)+abs($tempz);
                  if($tempL1==1){
                        $dist{$element} .= $tempL1;
                  } elsif($tempL1==0){
                        undef(%dist);
                        last;
                  }
         }
        foreach $element (keys %dist){
                 if ( ($HoA{$element}[3]>0)){ #potential monomer is good, so add to HoA and update bonds
                        my $newKey=scalar (keys %HoA);
                        if($newKey<=($PolymerSize-1)){
                         $HoA{$element}[3]--;
                         push @{$HoA{$newKey}}, $coordsNeighbors[0];
                         push @{$HoA{$newKey}}, $coordsNeighbors[1];
                         push @{$HoA{$newKey}}, $coordsNeighbors[2];
                         push @{$HoA{$newKey}}, $coordsNeighbors[3];
                         push @{$BondHoA{$element}}, "$newKey";
                         push @{$BondHoA{$newKey}}, "$element";
                         last;
                        }
                 }
              }
} while((scalar (keys %HoA))<=$PolymerSize-1);
foreach $element (keys %HoA){
        print "$element \t $HoA{$element}[0] \t $HoA{$element}[1] \t $HoA{$element}[2]\n";
}
Trying to remove extra "-1" from image src's in a string using preg_replace

Trying to remove extra "-1" from image src's in a string using preg_replace


By : Teeheehee
Date : March 29 2020, 07:55 AM
I hope this helps you . I've a big string with a ton of html in it and I'm trying to remove some extra -1 from the image urls which wordpress is adding for no obvious reason. , Use:
code :
$content = preg_replace('/-1(?!-1)/','',$content);
Related Posts Related Posts :
  • How to search a row that has been joined with another table
  • How to do mysql LEFT JOIN for Google multiple line chart (php, mysql)?
  • Find the two longest strings separated by dash in PHP
  • Cannot access private property with Set method in Symfony
  • How to compare 2 array of PHP objects then fill in empty string if data not match?
  • strtotime gives back false result to strings in an array
  • How to create Url that contain name and id laravel
  • Codeigniter: Models not working with an error: Undefined property: CI_Loader
  • How to use + or - operators as parameters in Doctrine prepared SQL statement?
  • PHP unpack overlfow variable memory limit
  • How to check the URL's structure using PHP preg_match?
  • PHP preg_replace - text will not be recognized
  • Show image from other domain without showing the domain name - PHP
  • How to run and watch local server at the same time?
  • Access form request from Observer laravel
  • single quote problem with preg_replace_callback
  • How to Create A Unique URL for each product enquiry form for Google Analytics Tracking
  • Laravel email configuration: what am I missing?
  • Assign indexed array values to multidimensional array?
  • Custom WordPress stylesheet not loading
  • Data attribute only returning first value
  • How to list all roles with Permissions,in spatie permission Package?
  • How to achieve this number pattern with n input
  • How to iterate array inside array data in laravel ,output are given below
  • To get output of movie with its genre
  • Extracting some data from a JS object literal string in PHP using Regex
  • axios and vuex are deleting wrong index in array
  • Setting empty CURLOPT_POSTFIELDS
  • Laravel 5.8 use subdomain as API endpoint beside domain.com/api
  • Error while add data in database SQL Server 2016
  • Does PhpStorm allow to skip PHPDoc tags when type hints is declared?
  • html classes are changed to Attributes
  • Using json to import multidimensional data
  • passing data from the view to the controller, where the data comes from another controller
  • How to extract integer and decimal numbers in PHP string correctly?
  • Parsing Sub-Object from an XML Feed with objects
  • Getting error "Unknown column 'text' in 'field list'"
  • How to properly get onedrive access token via php and curl
  • How to add spell check to a php function
  • Is it posible to create css rules with php?
  • Pretty URL with $_GET method
  • Wordpress always load same page - index.php
  • Find value in array and return with new from different array
  • PHP multiple file upload with different keys
  • Can't modify times one a time without weird errors
  • Get size of scraped image with domcrawler (Goutte)
  • Laravel - Ordering a collection of models
  • PHP Fatal error: Uncaught Error: Call to a member function setFetchMode() on boolean
  • Strict Standards: Only variables should be passed by reference in /main_dir/sub_dir/backup.php
  • Uncaught Google_Exception: (update) unknown parameter: 'copyRequiresWriterPermission'
  • Laravel 5 form does not redirect with old input
  • How to get values greater than or equal to in Mysql database sql when its a value like 1:00 PM?
  • PHP datediff overday issue
  • Masking an auto incrementing primary key
  • How to grab a String BEFORE a certain word
  • ZF2 Routing Multiple Controllers based on route constraints
  • How to deregister/dequeue jquery.sticky.js in Elementor (Pro)?
  • How to fix errors counting words in text plain with PHP?
  • How to get View data in Laravel in custom helper or directive
  • Creating a new data entry into a database with eloquent and trying to access the variable in the url
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org