Jump to content

Clarissa

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Clarissa's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm upgrading my localhost (XAMPP) to PHP 5.3.8 from 5.3.1. While everything else seems to be working fine, ssh2 is confounding me: when I run a script it hangs for a bit then a "connection to the server was reset" message. shh2 seems to be properly installed so I don't know what else I can do. Here are the relevant details from both versions: 5.3.1 Registered PHP Streams: https, ftps, php, file, glob, data, http, ftp, compress.zlib, ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp, compress.bzip2, phar, zip ssh2 extension version 0.11.0-dev libssh2 version 1.1 banner SSH-2.0-libssh2_1.1 remote forwarding enabled hostbased auth enabled polling support enabled publickey subsystem enabled libeay32.dll/ssleay32.dll = 0.9.8.12 ---------------------------------------------- 5.3.8 Registered PHP Streams: php, file, glob, data, http, ftp, zip, compress.zlib, ssh2.shell, ssh2.exec, ssh2.tunnel, ssh2.scp, ssh2.sftp, compress.bzip2, phar ssh2 extension version 0.11.2 libssh2 version 1.2.7 banner SSH-2.0-libssh2_1.2.7 remote forwarding enabled hostbased auth enabled polling support enabled publickey subsystem enabled libeay32.dll/ssleay32.dll = 0.9.8.18 Did something happen between these PHP versions that could cause such an error? And if so, is it fixable? I already have phpseclib on standby in case this isn't resolved, I'd just prefer not to have to rewrite all my scripts if at all possible. Thank you.
  2. I recently switched to Rapid PHP 2010, the list of features is insane, a real pleasure to use and damn cheap considering everything it does. http://www.blumentals.net/rapidphp/
  3. Hi. I need to enable multiple uses of preg_replace_callback within the same script, which otherwise leads to an error due to an inability to redeclare function. Been messing around trying to come up with something, no luck so far: if ($count > 0) { for ($i=0; $i<count($match[0]); $i++) function name($match) { return($match[1])[$i]; } $foo = preg_replace_callback("#\<tag\>[REGEX]\<\/tag\>#", "name", $bar); } Any ideas how to get this working? Thanks.
  4. Oh wow, that was exactly what I needed, it does everything I require without compromising the other data, thanks so much!!! Thanks, but preg_replace_callback() did the trick! However, you can help this silly gal out with another, obviously simple problem: I want to parse, process and then overwrite only 1 specific column in the file, I'm fine with the first two steps but am having issues with the third. Here's what I have so far: <?php $fh = fopen("data.csv", "r"); $row = 1; while (($data = fgetcsv($fh, 1024, ",")) !== FALSE) { $get = $data[2]; $uc = ucwords(strtoupper($get)); echo $uc; echo "</br>"; } ?> That displays fine, I just need it to be written back into it's original column. I know this is done with fputcsv, but I can't seem to get it to work: $fp = fopen('data.csv', 'w'); fputcsv($fp, $uc, ","); fclose($fp); That wipes the file.
  5. I'm trying to find a suitable alternative to file_put_contents for the purpose of overwriting a column of entries in a csv file. I'm using preg_match_all to extract certain words out of one column and want them to replace their original strings without affecting the rest of the file. The following code gets the job done but at the expense of the other columns i.e. they get wiped: <?php $fh = fopen('data.csv', 'r'); $str = fread ($fh, filesize('data.csv')); preg_match_all('/%REGEX%/', $str, $matches); file_put_contents('data.csv', implode("\r\n", $matches[1])); fclose($fh); ?> I've been toying around with it and this is the closest that comes to what I'm after: <?php $fh = fopen('data.csv', 'r'); $str = fread ($fh, filesize('data.csv')); preg_match_all('/%REGEX%/', $str, $matches); foreach($matches[1] as $value) $output = preg_replace('/%REGEX%/', $value, $str); $filename = "data.csv"; $write = $output; $filehandle = fopen($filename, 'w'); fwrite($filehandle, $write); fclose($filehandle); ?> That preserves the other columns and data but only the last extracted word gets repeatedly written, throughout the entire column, on every single row. Arrays aren't yet my forte so I'm guessing the solution is somewhere in that dept. Is there maybe a simpler way to do this, perhaps with preg_replace? Also, the csv file's integrity gets messed up if a non-match results in a deleted cell, so a substitute entry is required if no match is found. Any ideas? Thanks.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.