Count a sub-string inside a string
<pre><code>$string = "This is &lt;a href="http://www.google"&gt;a&lt;/a&gt; string with a link and I want to count the value of href attribute"
</code></pre>

<p>I have a string, and I want to output 10 characters from that string in html.</p>

<p>The problem is that I echo out 10 characters but I count also the chars inside the a tag. I could just simple ad the strlen of <code>"&lt;a href=""&gt;&lt;/a&gt;</code>" but I will never now the length of the value of href attr. How I find that value?</p>

<p>Edit:</p>

<p>On a blog there is an excerpt you see in a sidebar, not the hole post. I use a custom function to get the excerpt by counting the letters. I want like 100 character from the post. I want also to keep an eventual link. But the function counts also the character "&lt; a href="..." > &lt; / a >" and the final string is shorter. I just wanted to find out the length of that dynamically generated href value to add it to my excerpt length variable.</p>

<p>Is this clear enough or i'll get another minus?</p>
