Jump to content

function doesnt work, doesnt output data


jesushax

Recommended Posts

hi below is my function

 

f
unction paragraphs($data) {
$data = str_replace('<br />', '', $data);
$data = preg_replace('%\A\s*<p>|</p>\s*\z%', '', $data);
htmlspecialchars($data);
}

 

$Case = paragraphs($_POST["txtCase"]);

 

i didnt create the function code i just sued it but the idea of the code is to

remove the <p> if the data sent has one at the begining

remove the </p> if the data has one at the end

remove all <br /> tags

 

thanks for any help

 

at the moment the function posts nothing, blank data only...

Link to comment
https://forums.phpfreaks.com/topic/110031-function-doesnt-work-doesnt-output-data/
Share on other sites

just looking at the code

 

function paragraphs($data) {
$data = str_replace('<br />', '', $data);
$data = preg_replace('%\A\s*<p>|</p>\s*\z%', '', $data);
return htmlspecialchars($data);
)

 

htmlspecialchars converts say > to >

 

but i want the <p></p> html tags in the middle i just want the ones removed from the end and the begining if there are any if there arent do dont anything, the code above do this?

Sorry, I didn't read your post properly.

 

well, one thing you could do is:

 

<?php

$text = '<p>This is some text. <p>Another paragraph</p> Some more text</p>';

if(substr($text, 0,3) == '<p>' && substr($text, -4) == '</p>') {

	$text = substr($text, 3);
	$text = substr($text, 0, -4);
}

echo $text;
?>

 

 

ok heres my finale, this good?

 

strip_tags($data, "<p>")
if(substr($data, 0,3) == '<p>' && substr($data, -4) == '</p>') {
$data = substr($data, 3);
$data = substr($data, 0, -4);
str_replace("<p>","</p><p>",$data);
echo $data;

 

so all other html will be stripped apart from <p> tags

then if it begins or ends with <p> it will be removed

then any <p> inside the text will be replaced with </p><p>

 

what about symbols like & and ' they come up as & etc.. are they classed as html tags will they be stripped?

 

Thanks

final one is here

 

function paragraphs($data) {
strip_tags($data, "<p>")
if(substr($data, 0,3) == '<p>' && substr($data, -4) == '</p>') {
$data = substr($data, 3);
$data = substr($data, 0, -4);
}
str_replace("<p>","</p><p>",$data);
str_replace("</p><p></p><p>","</p><p>",$data);
echo $data;
}

 

this work well?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.