hello friends,
i have recently started coding PHP, so i am still at beginners stage, so please bear me if you found this very silly question.
What i want is to add a particular code after say first 100 characters in my post.
say i have a post of 1000 words and after initial say 100 words i want to add a new tag of ream more, that tag is <!--more-->.
so after first 100 characters this tag should come and then the rest of post should.
so is there any function in PHP which let me allow few words in somewhere middle of any post?
Waiting for the reply and thanking of you in advance.
Regards,
Hemanshu Patel
http://www.tutorialsforu.info
http://www.articlesdir.co.cc
strange requirement with PHP
Moderator: General Moderators
-
hemanshurpatel
- Forum Newbie
- Posts: 6
- Joined: Wed Sep 10, 2008 6:25 am
Re: strange requirement with PHP
You can use substr_replace with a $length of zero...
-
hemanshurpatel
- Forum Newbie
- Posts: 6
- Joined: Wed Sep 10, 2008 6:25 am
Re: strange requirement with PHP
i think you didnt get my problem
how can use substr_replace
i dont know what i need to replace with, as i dont know what word it will be at the end of 100 characters.
how can use substr_replace
i dont know what i need to replace with, as i dont know what word it will be at the end of 100 characters.
Re: strange requirement with PHP
Okay, you've said two very different things in your post, so if you could just clear up whether you want to insert your text after the 100th character or the 100th word that would help immensely. I'm assuming you mean characters, because that makes more sense.
Here's an example for using substr_replace..
Outputs
You would just use something like substr_replace($string,'<!-- more -->',100,0)
Here's an example for using substr_replace..
Code: Select all
<?php
$string = "1234567890";
echo substr_replace($string,'[!-- example --]',5,0);
?>Code: Select all
12345[!-- example --]67890-
hemanshurpatel
- Forum Newbie
- Posts: 6
- Joined: Wed Sep 10, 2008 6:25 am
Re: strange requirement with PHP
yeah, thats what exactly i want
let me try this
let me try this