Viewed   81 times


$xml = "l";
$xml = "vv";

echo $xml;

This will echo vv. Why and how can I do multi-line strings for things like SimpleXML, etc.?




$xml = "l


You can also use the following:

$xml = "lnvv";


$xml = <<<XML

Edit based on comment:

You can concatenate strings using the .= operator.

$str = "Hello";
$str .= " World";
echo $str; //Will echo out "Hello World";
Thursday, August 25, 2022

You need a Ajax call to pass the JS value into php variable

JS Code will be (your js file)

var jsString="hello";
    url: "ajax.php",
    type: "post",
    data: jsString

And in ajax.php (your php file) code will be

$phpString = $_POST['data'];     // assign hello to phpString 
Thursday, November 10, 2022

alert('my name is: <?php echo $man; ?>' );

Friday, August 19, 2022

A little digging in the Python source code shows that TestCase registers a bunch of methods to test equality for different types.

self.addTypeEqualityFunc(dict, 'assertDictEqual')
self.addTypeEqualityFunc(list, 'assertListEqual')
self.addTypeEqualityFunc(tuple, 'assertTupleEqual')
self.addTypeEqualityFunc(set, 'assertSetEqual')
self.addTypeEqualityFunc(frozenset, 'assertSetEqual')
    self.addTypeEqualityFunc(unicode, 'assertMultiLineEqual')
except NameError:
    # No unicode support in this build

You can see that unicode is registered to use assertMultiLineEqual(), but str is not registered for anything special. I have no idea why str is left out, but so far I have been happy with either of the following two methods.

Call Directly

If an 8-bit string isn't registered to use assertMultiLineEqual() by default, you can still call it directly.

def testString(self):
    a = 'xaxnzzz'
    b = 'xbxnzzz'
    self.assertMultiLineEqual(a, b)

Register String Type

You can also register it yourself. Just add an extra line to your test case's setUp() method. Do it once, and all your test methods will use the right method to test equality. If your project has a common base class for all test cases, that would be a great place to put it.

class TestAssertEqual(unittest.TestCase):
    def setUp(self):
        super(TestAssertEqual, self).setUp()
        self.addTypeEqualityFunc(str, self.assertMultiLineEqual)

    def testString(self):
        a = 'xaxnzzz'
        b = 'xbxnzzz'
        self.assertEqual(a, b)

    def testUnicode(self):
        a = u'xaxnzzz'
        b = u'xbxnzzz'
        self.assertEqual(a, b)

Either of these methods will include highlighting when the string comparison fails.

Saturday, August 27, 2022

Just use the new lines directly.

"email" = "Hello %@,

Check out %@.


Monday, October 10, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :