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
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?

Link to comment
Share on other sites

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;
?>

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.