php,string,truncation,mbstringRelated issues-Collection of common programming errors
Mohammad
php netbeans character-encoding whitespace file-encodings
I’m editing the functions.php file of a WordPress theme and whenever I edit it, even when the edit is adding a single space the server returns error:Parse error: syntax error, unexpected ‘}’ in /theme/functions.php on line 1 This is where I add the single space:<?php load_theme_textdomain(‘theme’, get_template_directory() . ‘/languages’); <- I added a single space hereand everything dies after that. This is not a consistent error, as it goes away after I replace the whole functions.p
netcoder
php unit-testing sockets
Greetings Stackoverflowers,I have an application in which a communication abstraction layer exists. Each implementation in this layer, called a connector, provides my application with a way of exchanging data with a connected peer (e.g.: through HTTP, TCP sockets, UDP sockets, etc.).Per example, I have a Connector_Tcp class that implements methods such as read, write, open and close.I need to write a unit test for that class. I know that unit tests should have as less dependencies as possible. U
Taffman
php tags fgets
I’m using fgets to read a text file that contains field names delimited with the “<” and “>” characters. It seems like fgets is seeing these field names as tags and stripping them. I thought that only fgetss stripped tags and that fgets should allow this. I’m testing this with the following code:<?php $handle = @fopen(“Test.txt”, “r”); if ($handle) {while (($buffer = fgets($handle, 4096)) !== false) {echo $buffer;}if (!feof($handle)) {echo “Error: unexpected fgets() fail\n”;}fclose($handle
Chris
php
I’m not sure how simple is this to solve, but I assume I’m doing something wrong. I’m new to PHP, so bear with me, please.When I started learning PHP, I always placed all my project files into the same folder along with index.php and thus included everything like this:<?php include(‘./translation.php’); ?>Later on in the process of learning as I gained experience and my skill increased, I had to start using folders and place my files into sub folders. I ended up successfully including my f
DarkCthulhu
php string utf-8 comparison
I’m trying to compare two string lets say Émilie and Zoey. Well ‘E’ comes before ‘Z’ but on the ASCII chart Z comes before É so a normal if ( str1 > str2 ) Won’t work. I tried with if (strcmp(str1,str2) > 0) still don’t work. So i’m looking into a native way to compare string with UTF-8 characters.
meder
php javascript html validation dom
I’m looking for something like http://validator.nu/, I’ll be validating html input ( string ) and I want to notify the user if there are any missing end tags, whether a certain element can’t have a certain attribute, things of that nature ( HTML 4.01 Strict validation basically ).Sidenote: I won’t be dealing with XML/DTDs, and I don’t want to correct the user input like how http://htmlpurifier.org/ does it.
PeeHaa
php
I have a bit of a general dissatisfaction about the way passing by reference works in PHP, coming from a Java background myself. This might have been talked about before on SO, so I’m sorry if this might seem redundant.I’m going to give a code example to make things clear. Say we have a Person class:<?phpclass Person {private $name;public function __construct($name){$this->name = $name;}public function setName($name){$this->name = $name;}public function getName(){return $this->name;
user1615069
php logging
Well…I do know it’s good to log errors when the website is in production and error reporting is off. But what should I actually log? I can’t log all errors, so I should to choose some most errors-probable places in the code and call the function with some message to log this. Should I use try-catch to do this? And is it actually the best way to do this?
NullPoi?te?
php mysql
PHP variable not working in sql query..Am just a begginer in php. pls tell where am going wrong.thanks in advances.$sql = ‘SELECT email_id FROM dealer WHERE dealerid=”‘mysql_real_escape_string($id).'”‘;$rt = mysql_query($sql); $row = mysql_fetch_row($rt);if($row) {echo “<h1>Number:</h1>” . $row[0];while($row = mysql_fetch_assoc($rt)) {var_dump($row);} }
Galen
php validation date datetime language-agnostic
I’m working on date validation for a validation library. A date format and a variable containing the date to validate will be supplied to the library.$validator->validate( $_POST[‘date’], ‘m/d/y’ );It’s pretty easy to do basic validation with DateTime::createFromFormat()if ( DateTime::createFromFormat( $format, $date ) !== false ) {// “valid” date }My issue is that with this method invalid dates such as 23/23/23 pass because the DateTime class will shift the date and set it to 2024-11-23. I
DarkCthulhu
php string utf-8 comparison
I’m trying to compare two string lets say Émilie and Zoey. Well ‘E’ comes before ‘Z’ but on the ASCII chart Z comes before É so a normal if ( str1 > str2 ) Won’t work. I tried with if (strcmp(str1,str2) > 0) still don’t work. So i’m looking into a native way to compare string with UTF-8 characters.
ThiefMaster
string r ggplot2 aesthetics
This question already has an answer here:Use character string as function argument2 answersI have the following problem.I want to turn a string e.g> a<-paste(‘x=col1,y=col2,fill=col3′)into a form that aes_string accepts like this: x=’col1′,y=’col2’,fill=’col3’this is part of a function:>fun<-function(data,aes.string=”){ aes_mapping <- aes_string(aes.string) p <- ggplot(df.data,mapping=aes_mapping ) p <- p + geom_point() return(p) }if i call> fun(df.sam,a) > Error in
Arkaitz Jimenez
string binary erlang
I am writing an erlang module that has to deal a bit with strings, not too much, however, I do some tcp recv and then some parsing over the data.While matching data and manipulating strings, I am using binary module all the time like binary:split(Data,<<“:”>>) and basically using <<“StringLiteral”>> all the time.Till now I have not encounter difficulties or missing methods from the alternative( using lists) and everything is coming out quite naturally except maybe for add
yaki_nuka
java string duplicates
I want to ask a question about avoiding String duplicates in Java.The context is: an XML with tags and attributes like this one:<product id=”PROD” name=”My Product”…></product>With JibX, this XML is marshalled/unmarshalled in a class like this:public class Product{ private String id; private String name; // constructor, getters, setters, methods and so on }The program is a long-time batch processing, so Product objects are created, used, copied, etc.Well, the question is: When I a
sawa
ruby string
Suppose I have a string “I am a good boy”. I want the total count of each letter present in the string. Letters are case sensitive. i.e., D and d need to be considered as two different characters.
Macdiesel
python string md5
I’m working on a python project in 2.6 that also has future support for python 3 being worked in. Specifically I’m working on a digest-md5 algorithm. In python 2.6 without running this import: from __future__ import unicode_literalsI am able to write a piece of code such as this:a1 = hashlib.md5(“%s:%s:%s” % (self.username, self.domain, self.password)).digest() a1 = “%s:%s:%s” %(a1, challenge[“nonce”], cnonce )Without any issues, my authentication works fine. When I try the same line of cod
Rohit Jain
java regex string split
I’m making a text based dice roller. It takes in strings like “2d10+5” and returns a string as a result of the roll(s). My problem is showing up in the tokenizer that splits the string into useful parts for me to parse into information.String[] tokens = message.split(“(?=[dk\\+\\-])”); This is yielding strange, unexpected results. I don’t know exactly what is causing them. It could be the regex, my misunderstanding, or Java just being Java. Here’s what’s happening: 3d6+4 yields the string array
romi
java string hex
Helo:I have a question, that I solved in c, but now I want to do it in hava: I have a String like: ‘\x03\x00\x00\x00’ This is representing an hexadecimal value of a integer. I transform to 0x03\0x00… And now I want to obtain the integer, but I don’t know how to do it in javacould someone give me some idea ?Thanks in advance(Is it some way to use this format (‘\x03\x00\x00\x00’ ) directly without use byte[] arrays? and in C can I use this format directly to build a integer (int)?)
Mr Lister
c# string numbers find-and-replace
The string can contains ints, floats and hexadecimal numbers for example.”This a string than can have -345 and 57 and could also have 35.4656 or a subtle 0xF46434 and more”What could I use to find these numbers in C#?
hakre
php string
I have a little problem with my script. When I try to run it I receive “Parse error: syntax error, unexpected T_STRING” as long as I have ‘ sign in my code. When I change all ‘ into ” then I have the same error. So I have to change all ” into ‘. Here is my code:<?phpPutEnv(TNS_ADMIN=’C:\Programy\OracleDeveloper10g\NETWORK\ADMIN\’);$conn = oci_connect(“user”, “pass”, “dbstring”);if (!$conn){$e = oci_error();print $e;exit;}else{$stmt = OCIParse($conn, “SELECT password FROM USERS WHERE username=
Adrian
r truncation
Am I missing something?library(truncreg)n <- 10^4 lambda <- 0.3 # Proba y is taken from component 0df <- data.frame(x=rnorm(n)) df$y0 <- pmax(rnorm(n, 10 + df$x, 5), 0) df$y1 <- pmax(rnorm(n, 2 – 5*df$x, 2), 0) df$component <- ifelse(runif(n) < lambda, 0, 1) df$y <- ifelse(df$component == 0, df$y0, df$y1) # Mixture of censored regressionsplot(df$x, df$y)model <- truncreg(y ~ x, data=df) # All data model.w <- truncreg(y ~ x, data=df, weights=component) # Only com
Dale
c++ truncation
I have just joined a team that has thousands of lines of code like:int x = 0; x=something(); short y=x; doSomethingImportantWith(y); The compiler gives nice warnings saying: Conversion of XX bit type value to “short” causes truncation. I’ve been told that there are no cases where truncation really happens, but I seriously doubt it. Is there a nice way to insert checks into each case having the effect of: if (x>short.max) printNastyError(__FILE,__LINE); before each assignment? Doing this ma
Ira Baxter
windows logging console truncation
We build complicated console-based tools that produce a lot of commentary on the console. These tools process a lot of data and so runs are expensive and we don’t like to do them more often than necessary, especially during testing where we already have to run them repeatedly. During such tests, we often log the result to a file to capture this commentary for inspection:C:> [ourcommand] >log.txt When the application runs to completion, this works great.If the application crashes (illegal mem
Oldskool
php string truncation mbstring
Months ago I made a short code that uses mb_strimwidth() to exactly fit some text into a table cell, putting dots at the end of a truncated string. Now, after some times, I tried to execute that same code and it went out with this error:Fatal error: Call to undefined function mb_strimwidth() in …I tried to find the mbstring.php file, and when I found the mb_strimwidth() function, I discovered that it is not implemented anymore. How is that possible? But my main question is: how can I get the s
PeeHaa
php character-encoding iconv mbstring
Is it possible, prior to converting a string from a charset to another, to know whether this conversion will be lossless?If I try to convert an UTF-8 string to latin1, for example, the chars that can’t be converted are replaced by ?. Checking for ? in the result string to find out if the conversion was lossless is obviously not a choice.The only solution I can see right now is to convert back to the original charset, and compare to the original string:function canBeSafelyConverted($string, $from
user575228
install phpmyadmin mbstring
http://stackoverflow.com/questions/4327230/phpmyadmin-install-errorsHaving some issues with installing phpMyAdmin. I would like to resolve the following issue, but don’t have a clue where to start (except maybe php.ini?).Here’s the error message.The mbstring PHP extension was not found and you seem to be using a multibyte charset. Without the mbstring extension phpMyAdmin is unable to split strings correctly and it may result in unexpected results.And here’s a related article I found on SO that
Charles
php mbstring
I’m trying to install indefero on a CentOS 5.3 VMware ‘box’ and I ran into a problem. Quite early in the installation I get an error that I’ve been able to narrow down to this:[root@code /var/www/html]# cat x.php<?phpmb_internal_encoding(“UTF-8”);?> [root@code /var/www/html]# php x.php PHP Fatal error: Call to undefined function mb_internal_encoding() in /var/www/html/x.php on line 2I get the same error when calling this script via http through Apache. Now according to the PHP manual the
Oldskool
php string truncation mbstring
Months ago I made a short code that uses mb_strimwidth() to exactly fit some text into a table cell, putting dots at the end of a truncated string. Now, after some times, I tried to execute that same code and it went out with this error:Fatal error: Call to undefined function mb_strimwidth() in …I tried to find the mbstring.php file, and when I found the mb_strimwidth() function, I discovered that it is not implemented anymore. How is that possible? But my main question is: how can I get the s
Danny Beckett
php centos centos6 phpinfo mbstring
I have tried to install the mbstring module for PHP. I have entered the below commands:yum install php-mbstring /usr/local/apache/bin/apachectl restartModule is now installed but the errors has not dissapeared.Fatal error: Call to undefined function mb_send_mail() In my phpinfo(), “mbstring” doesn’t exist…OS: centos 6 PHP: 5.3.8
Yogesh Suthar
php phpmyadmin mbstring
I’m receiving an error message whilst trying to access PHPMyAdmin on IIS 7.5. I’ve checked phpinfo and have the following information for mbstring;Multibyte Support: enabled Multibyte string engine: libmbfl HTTP input encoding translation: disabled libmbfl version: 1.3.2mbstring.detect_order: no value mbstring.encoding_translation: Off mbstring.func_overload: 0 mbstring.http_input: pass mbstring.http_output: pass mbstring.http_output_conv_mimetypes: ^(text/|application/xhtml\+xml) mbstring.inter
spaniard
php joomla fatal-error mbstring
I got stuck into this problem and I can’t seem to find a solution.The version of PHP installed in the server is 5.3.22. After installing Joomla and the default sample data I got this error accessing the web site:Fatal error: Call to undefined function mb_strpos() in /public_html/site/templates/yoo_sync/layouts/module.php on line 115I checked the phpinfo page and I noticed that option –enable-mbstring is missing:I spoke with the hosting company’s support team and they told me to add the followin
zachar
php symfony2 debian mbstring
I’m getting errorCall to undefined function FOS\UserBundle\Util\mb_convert_case() app_path/vendor/bundles/FOS/UserBundle/Util/Canonicalizer.php on line 18It occurs when I try to load fixtures.First step was to install mbstring.so ext, so I compiled php with –enable-mbstringthan successfully copiled mbstring extphpize ./configure make make installand addedextension=mbstring.soto my php.ini file. Unfortunately I still got that error and php -m doesn’t display mbstring as loaded extension. What’s
Sergey
php symfony2 mamp mbstring
On my Symfony2 application, I am receiving an error:Fatal error: Call to undefined function FOS\UserBundle\Util\mb_convert_case() in /Applications/MAMP/htdocs/application/vendor/bundles/FOS/UserBundle/Util/Canonicalizer.php on line 18I am using PHP 5.3.6.Here is my PHPInfo showing that mbstring is enabled:http://i.stack.imgur.com/FCMDv.pngIf mbstring is enabled then why is mb_convert_case not being found?
patrick
php apache2.2 mbstring
I want to use simpleHTMLDom in my development environment, a Windows server running Apache 2.2 and PHP 5.3.14 (downloaded from Apache). I want to enable mbstring (extension=php_mbstring.dll), but I see the following error in the PHP logs when I restart Apache:PHP Warning: PHP Startup: Unable to load dynamic library ‘C:\PHP\ext\php_mbstring.dll’ in Unknown on line 0The DLL file is there. I found on php.net that nbstring needs libmbfl to work. I can not find how to get libmbfl to work though. I ca
Web site is in building