Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

String-Analyse HTMLText in php does not work


Go to End


4 Posts   1165 Views

Avatar
Lukin

Community Member, 56 Posts

17 July 2015 at 12:39am

Hi,
I try to do some strpos/substr-stuff with the content of an HTMLText-Field. But it seems, that instead of having the plane html-code, it's encoded in some way.
In example strpos('<p>',$this->Content); returns false... But there are several p-tags in the field.

What is happning?

Thanks in advance for any advice
Lukin

Avatar
swaiba

Forum Moderator, 1899 Posts

17 July 2015 at 1:57am

Is it really returning false? or maybe it returns zero as <p> is at position zero?

Alternatively, please post the string content of the page as I could only come up with the above...

Avatar
Pyromanik

Community Member, 419 Posts

18 July 2015 at 12:13am

Could also try $this->dbObject('Content')->Value()

Avatar
Lukin

Community Member, 56 Posts

18 July 2015 at 3:16am

Hi,

sorry my fault. I inverted the parameters for strpos....
Maybe you like the idea. One HTMLText- field
and you can add a class ('additionalcolumn') to split it into two 'physical' columns.

Useful for me, cause the client has very short text mostly , which is aligned to center.
If he has a long text he can split it into two columns now by adding the class 'additionalcolumn' to the element which is on the 'splitpoint'.
Gives a much better visual experience for the visitor ;) Might be intersting for responsive proposals too...

public function getContent01(){
$string=$this->dbObject('Content')->Value;
$tagPos=strpos($string,'additionalcolumn');
if($tagPos){
$end=strrpos(substr($this->Content,0,$tagPos),'<',0);
return substr($this->Content,0,$end);
}else{
return $this->Content;
}
}
public function getContent02(){
$tagPos=strpos($this->Content,'additionalcolumn');
if($tagPos){
$start=strrpos(substr($this->Content,0,$tagPos),'<',0);
return substr($this->Content,$start);
}else{
return false;
}
}
In template you can ask for the getContent02 to decide if you want a one or two column layout...