Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP substr doesn't echo anything
    primarykey
    data
    text
    <p>I'm having problems with this code, and the PHP method 'substr' is playing up. I just don't get it. Here's a quick introduction what I'm trying to achieve. I have this massive XML-document with email-subscribers from Joomla. I'm trying to import it to Mailchimp, but Mailchimp have some rules for the syntax of the ways to import emails to a list. So at the moment the syntax is like this: </p> <pre><code>&lt;subscriber&gt; &lt;subscriber_id&gt;615&lt;/subscriber_id&gt; &lt;name&gt;&lt;![CDATA[NAME OF SUBSCRIBER]]&gt;&lt;/name&gt; &lt;email&gt;THE_EMAIL@SOMETHING.COM&lt;/email&gt; &lt;confirmed&gt;1&lt;/confirmed&gt; &lt;subscribe_date&gt;THE DATE&lt;/subscribe_date&gt; &lt;/subscriber&gt; </code></pre> <p>I want to make a simple PHP-script that takes all those emails and outputs them like this:</p> <pre><code> [THE_EMAIL@SOMETHING.COM] [NAME OF SUBSCRIBER] [THE_EMAIL@SOMETHING.COM] [NAME OF SUBSCRIBER] [THE_EMAIL@SOMETHING.COM] [NAME OF SUBSCRIBER] [THE_EMAIL@SOMETHING.COM] [NAME OF SUBSCRIBER] </code></pre> <p>If I can do that, then I can just copy paste it into Mailchimp. </p> <p>Now here's my PHP-script, so far:</p> <pre><code>$fileName = file_get_contents('emails.txt'); foreach(preg_split("/((\r?\n)|(\r\n?))/", $fileName) as $line){ if(strpos($line, '&lt;name&gt;&lt;![CDATA[')){ $name = strpos($line, '&lt;name&gt;&lt;![CDATA['); $nameEnd = strpos($line, ']]&gt;&lt;/name&gt;', $name); $nameLength = $nameEnd-$name; echo "&lt;br /&gt;"; echo " " . strlen(substr($line, $name, $nameLength)); echo " " . gettype(substr($line, $name, $nameLength)); echo " " . substr($line, $name, $nameLength); } if(strpos($line, '&lt;email&gt;')){ $var1 = strpos($line, '&lt;email&gt;'); $var2 = strpos($line, '&lt;/email&gt;', $var1); $length = $var2-$var1; echo substr($line, $var1, $length); } } </code></pre> <p>The first if-statement works as it should. It identifies, if there's an ''-tag on the line, and if there is, then it finds the end-tag and outputs the email with the substr-method. </p> <p>The second if-statement is annoying me. If should do the same thing as the first if-statement, but it doesn't. The length is the correct length (I've checked). The type is the correct type (I've checked). But when I try to echo it, then nothing happens. The script still runs, but it doesn't write anything. </p> <p>I've played around with it quite a lot and seem to have tried everything - but I can't figure it out.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload