php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79598 update string function docs please
Submitted: 2020-05-14 17:35 UTC Modified: 2020-05-24 04:22 UTC
From: danwassonpgh at hotmail dot com Assigned:
Status: No Feedback Package: Strings related
PHP Version: 7.4.6 OS:
Private report: No CVE-ID: None
 [2020-05-14 17:35 UTC] danwassonpgh at hotmail dot com
Description:
------------
Could the documentation on php.net under  'PHP Manual > Function Reference > Text Processing Strings > String Functions' mention how some of the functions (substr, strpos), handle html special chars? The example in the "Test script" shows the confusion I encountered before learning by coding and running the "Test script". Thank you


Test script:
---------------
$stringA = 'Lorem ipsum, <x> sit amet, consectetur </x> adipiscing';

$substrA1 = substr($stringA, 0, 24);

$substrA2 = substr(htmlspecialchars($stringA), 0, 24);

$stringB = 'Lorem ipsum, xxx sit amet, consectetur xxxx adipiscing';

$substrB1 = substr($stringB, 0, 24);

$substrB2 = substr(htmlspecialchars($stringB), 0, 24);


echo '<pre>';
echo '<br> ..............................|----|----1----|----2----|----3----|----4----|----5----|';
echo '<br> $stringA  as htmlspecialchars |' . htmlspecialchars($stringA) . '|';
echo '<br> $substrA1 as raw              |' . $substrA1 . '|';
echo '<br> $substrA1 as htmlspecialchars |' . htmlspecialchars($substrA1) . '|';
echo '<br> $substrA2 as raw              |' . $substrA2 . '|';
echo '<br> $substrA2 as htmlspecialchars |' . htmlspecialchars($substrA2) . '|';
echo '<br> $stringB  as htmlspecialchars |' . htmlspecialchars($stringB) . '|';
echo '<br> $substrB1 as raw              |' . $substrB1 . '|';
echo '<br> $substrB2 as htmlspecialchars |' . $substrB2 . '|';
echo '<br></pre>';


Actual result:
--------------

 ..............................|----|----1----|----2----|----3----|----4----|----5----|
 $stringA  as htmlspecialchars |Lorem ipsum, <x> sit amet, consectetur </x> adipiscing|
 $substrA1 as raw              |Lorem ipsum,  sit ame|
 $substrA1 as htmlspecialchars |Lorem ipsum, <x> sit ame|
 $substrA2 as raw              |Lorem ipsum, <x> s|
 $substrA2 as htmlspecialchars |Lorem ipsum, &lt;x&gt; s|
 $stringB  as htmlspecialchars |Lorem ipsum, xxx sit amet, consectetur xxxx adipiscing|
 $substrB1 as raw              |Lorem ipsum, xxx sit ame|
 $substrB2 as htmlspecialchars |Lorem ipsum, xxx sit ame|

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-05-14 18:06 UTC] requinix@php.net
-Status: Open +Status: Feedback -Package: Documentation problem +Package: Strings related
 [2020-05-14 18:06 UTC] requinix@php.net
Not sure what you're talking about. substr and most other string functions *do not* handle HTML characters. They don't care.

It seems like the issue you're dealing with is that you're viewing the output from PHP as it's being rendered by your browser. Emphasis on "rendered". Oftentimes you need to be doing a View Source to see the raw output instead.
 [2020-05-24 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC